繁体   English   中英

为什么我的列表视图无法点击?

[英]Why is my listview unclickable?

我有一个布局的列表视图,它打印出一些信息,由于某种原因,当我单击它没有突出显示的每个元素时,告诉我我的列表视图是不可点击的。 这是我的代码。

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

该适配器使我可以在后台 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;
}
  }

我觉得奇怪的是突然我的列表视图无法点击,希望有人能弄清楚这是为什么。 谢谢

这可能会奏效。

list.setClickable(true); 

编辑:您可能还需要

list.setEnabled(true); 

这可能有效:

ListView lv = getListView();
lv.setClickable(true);
lv.setEnabled(true);

如果你想做一些 onclick 那么你必须 go 来添加 setOnClickListener(lv)。 有时你可能不知道 ListView 是可点击的,因为点击时它的颜色不会改变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM