我有一个带有数组适配器的 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();
}}
为什么会发生这种情况,我可以解决谁?谢谢!