2013-10-30 42 views
0

是否有可能使列表视图项可点击和可选?使列表视图项可点击和可选

如果我设置 机器人:textIsSelectable = “真”

我onitemclicklistener不起作用。或者有可能在不使用textIsSelectable的情况下突出显示listview中的textview?因为我用下面的xml代码在我的文本视图中创建突出显示

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <!-- Selected --> 
    <item 
    android:state_focused="true" 
    android:state_selected="false" 
    android:drawable="@drawable/focused"/> 
    <item android:drawable="@color/black" /> <!-- default --> 
</selector> 
+0

请这个答案http://stackoverflow.com/questions/8565999/how-to-highlight-选择项功能于列表视图 – hakim

回答

0

我认为你需要做一个自定义的listview。 LinearLayout listView =(LinearLayout)findViewById(R.id.listview);返回列表视图。 将子项目视图添加到listView中。 所以现在您可以在子项目视图上添加选择器和clicklistener。

0

这是我的wertherApp代码:

public class MainListAdapter extends BaseAdapter : 

    public void change(ArrayList<MainListInfo> mainWether) { 

    if (mainWether == null) 

     this.mainWether = new ArrayList<MainListInfo>(); 

    else 

     this.mainWether = mainWether; 

    this.notifyDataSetChanged(); 

} 

    public void setcurtentitem(int curentitem) { 

    this.curentitem = curentitem; 

    this.notifyDataSetChanged(); 

} 

public class MainListAdapter extends BaseAdapter { 

    …… 
    if (position == curentitem) { 

     convertView.setBackgroundResource(R.drawable.bg_01_down); 

    } else { 

     convertView.setBackgroundResource(R.drawable.bg_01_up); 

    } 

…… 


} 

那么活动:

listview.setOnItemClickListener(new OnItemClickListener() { 

     @Override 

     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
       long arg3) { 

      adapter.setcurtentitem(arg2); 

     } 

    });