Business is so
item default background color is white
1 Select an item, the background color black
2 and then select the item background color white
3 There is a item has been selected, the background is black. Select another item in this item background color black, but before the item background color white
Trying to solve ah ~ ~ I'm a little ignorant
Reply:
In every one of the select event item ...
Which is set on the line
Reply:
Similar problems have been continuously so there are a few people ask, please refer them.
Reply:
Give a link, right?
Say nothing equal say, you say, right?
Reply:
I want to know what you words ...
Content ah!
Reply:
easy
public class ListBackground extends Activity {
private ListdataList = new ArrayList ();
private ListView lv;
private int clickPosition = -1;
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_list_background);
for (char tempChar = 'a'; tempChar <= 'z'; tempChar + +) {
dataList.add (String.valueOf (tempChar));
}
lv = (ListView) findViewById (R.id.listView1);
final MyAdapter ma = new MyAdapter ();
lv.setAdapter (ma);
lv.setOnItemClickListener (new OnItemClickListener () {
@ Override
public void onItemClick (AdapterView parent, View view,
int position, long id) {
if (position! = clickPosition) {
clickPosition = position;
}
else {
clickPosition = -1;
}
ma.notifyDataSetChanged ();
}
});
}
@ Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater () inflate (R.menu.activity_list_background, menu);.
return true;
}
private class MyAdapter extends BaseAdapter {
@ Override
public int getCount () {
return dataList.size ();
}
@ Override
public Object getItem (int position) {
return dataList.get (position);
}
@ Override
public long getItemId (int position) {
return position;
}
@ Override
public View getView (int position, View convertView, ViewGroup parent) {
TextView tv = new TextView (ListBackground.this);
tv.setText (dataList.get (position));
tv.setBackgroundColor (Color.WHITE);
if (position == clickPosition) {
tv.setBackgroundColor (Color.BLACK);
}
return tv;
}
}
}
Reply:
So very, multi Xie Daxia up! ~ ~ ~ Hey little meaning
Reply:
FindViewById find one just started using the controls to change the display state control in the item, the results found that changing the multiple item, tangled for a long time, had to use the position can be solved, thank you very much!
No comments:
Post a Comment