2013-10-30 40 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); 

     } 

    });