我用textview和複選框作爲listView的項目。我編寫的用於listview的代碼正常工作。但是,當我添加複選框到列表視圖onclicklistener事件現在不工作。我在XML文件中使用此代碼:爲什麼不在listView上工作onclicklistener?
我的XML代碼:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="right"
android:padding="3dp"
android:textSize="25sp" />
</LinearLayout>
我的Java代碼:
private class Adapter_collection extends ArrayAdapter<String> {
public Adapter_collection(Context context, int resource, int textViewResourceId,
String[] name_collection_tbl_collection) {
super(context, resource, textViewResourceId, name_collection_tbl_collection);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.listview_items, parent, false);
TextView txt_item_list_collection = (TextView) row.findViewById(R.id.textView_Item_Listview);
CheckBox checkBox=(CheckBox)row.findViewById(R.id.checkBox_Item_Listview);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(getApplicationContext(), String.valueOf(position), Toast.LENGTH_SHORT).show();
}
});
txt_item_list_collection.setText(name_collection_tbl_collection[position]);
return row;
}
}
list_collections.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent goTo_SubjectsActivity = new Intent(Collection_List_Activity.this, Subjects_Activity.class);
startActivity(goTo_SubjectsActivity);
Intent_values.id_collection = id_tbl_collection[arg2];
}
});
期待一些java代碼 ? – nobalG
你的java代碼在哪裏? –
可能重複的[android:無法點擊與imagebutton列表視圖行](http://stackoverflow.com/questions/11428303/android-cant-click-on-listview-row-with-imagebutton) –