Following is my source code,
I also tried isPressed , isClicked , but it still doesn’t work.
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
// This a new view we inflate the new layout
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.my_item_layout, parent, false);
}
MyItem myItem = getItem(position);
TextView direction = (TextView) convertView.findViewById(R.id.direction);
direction.setText(myItem .getDirection());
if(convertView.isSelected()){
convertView.setBackgroundResource(R.drawable.list_select_bar);
setTextColor(convertView, textIDs , R.color.white);
}else{
convertView.setBackgroundResource(R.color.light_white);
setTextColor(convertView, textIDs , R.color.black);
}
return convertView;
}
Actually , if I remove the convertView check block, I just need to register an onItemClickListener onto the listview… but if I do this , seems makes getView method meaningless. I am so struggled with this issue.
First , I appreciate that Sam gave me such a useful tip.
Following is my resolve procedure.
Write a selector file and below is its content. then put this list_background.xml into drawable folder
then in your item layout xml , using list_background like this:
…
android:background=”@drawable/list_background”
…
>
That’s it. No click listener or other method invoked in the source code.