Reputation: 1123
I have a Listview of layouts that prints out some information, for some reason when I click on each element it does not highlight, telling me that my listview is unclickable. Here is my code.
ListView lv = (ListView) findViewById(R.id.imtrackinglistview);
refreshList(response, lv);
static final ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
private void refreshList(String response, ListView lv) {
// removes the list and rebuilds it will choose different response
// string to get the refreshed times
list.removeAll(list);
SpecialAdapter adapter = new SpecialAdapter(this, list,
R.layout.imtracking_row_text,
new String[] { "name", "location" }, new int[] {
R.id.tvImtrackingName, R.id.tvImtrackingLocation });
lv.setAdapter(adapter);
The adapter is so that I can switch between background colors.
public class SpecialAdapter extends SimpleAdapter{
private int[] colors=new int[]{0x30FF0000, 0x300000FF};
public SpecialAdapter (AnotherlistviewActivity context, ArrayList<HashMap<String, String>> list, int resource, String[] from, int[] to){
super(context, list, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View view=super.getView(position, convertView, parent);
int colorPos=position%colors.length;
view.setBackgroundColor(colors[colorPos]);
return view;
}
}
I find it strange that suddenly my listview is unclickable, hopefully someone can figure out why this is. Thanks
Upvotes: 0
Views: 906
Reputation: 18509
If you want do something onclick then u must go for adding setOnClickListener(lv). Sometimes you may not know that ListView is clickable because it color doesnot change when clicked.
Upvotes: 1
Reputation: 8520
This may work:
ListView lv = getListView();
lv.setClickable(true);
lv.setEnabled(true);
Upvotes: 1
Reputation: 3079
This might work.
list.setClickable(true);
Edit: You might also need
list.setEnabled(true);
Upvotes: 1