-1

我有一个带有数组适配器的 ListView。出于某种原因,当我滚动列表时,我得到了这个阴影,当我停止它时就可以了。那是我的代码:

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();
}}

为什么会发生这种情况,我可以解决谁?谢谢!

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 回答