-1

I have a ListView with an arrayadapter. for some reason when i scroll the list i get this shadow and when i stop its ok. thats my code:

public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;

public MobileArrayAdapter(Context context, String[] values) {
    super(context, R.layout.listview, values);
    this.context = context;
    this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View rowView = inflater.inflate(R.layout.listview, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.label);
    textView.setText(values[position]);
    if(textView.getText() == "royi"){
        textView.setBackgroundColor(Color.GRAY);
    }else{
        textView.setBackgroundColor(Color.BLACK);
    }

    // Change icon based on name
    String s = values[position];

    System.out.println(s);
    return rowView;
}

}

public class Listwithbaseadapter extends ListActivity {

static final String[] MOBILE_OS = 
        new String[] { "Android", "iOS", "royi", "Blackberry", "Android", "iOS", "royi", "Blackberry", "Android", "iOS", "royi", "Blackberry", "Android", "iOS", "royi", "Blackberry",
    "Android", "iOS", "royi", "Blackberry", "Android", "iOS","Android", "iOS", "royi", "Blackberry", "Android", "iOS"};


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(new MobileArrayAdapter(this, MOBILE_OS));

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    //get selected items
    String selectedValue = (String) getListAdapter().getItem(position);
    Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
}}

why is it happening and who can i fix it? Thanks!

4

3 に答える 3

3

使用する

        ListView listView = getListView();
        listView.setCacheColorHint(0); 

あなたのListActivityで。

于 2012-06-03T10:47:30.687 に答える
2
ListView listView = getListView();

listView.setCacheColorHint(0);
于 2012-06-03T10:36:26.750 に答える
1

xml で、Listview に次のプロパティを追加します。

<ListView android:cacheColorHint="#00000000" ... />

それは問題を解決します。コードで動的に行う必要はありません。スクロール時に上下の影を削除したい場合は、次を追加することもできます。

<ListView android:fadingEdge="none" ... />

于 2012-09-26T07:33:56.790 に答える