【发布时间】:2015-01-26 15:47:55
【问题描述】:
我正在使用一个 Listfragment,它有一个带有自定义图像的复选框,在 state_checked 上会发生变化。
但 'onListItemClick' 功能仅在其布局中的复选框被分配给 android:focusable="false" 和 android:clickable="false" 时才有效。
在这种情况下,复选框的自定义图像更改不起作用。
有没有办法同时完成两者。感谢任何帮助。
public class SympFragment extends ListFragment implements OnClickListener {
private ListView lv;
private String listview_array[] = {
"Text1",
"Text2",
"Text3",
"Text4",
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_symp, container, false);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
R.layout.ch_row, listview_array);
setListAdapter(adapter);
return rootView;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
switch( position )
{
case 0: Toast.makeText(getActivity().getApplicationContext(), "Well Done!", Toast.LENGTH_LONG).show();
break;
}
}
}
布局:
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chcheckbox"
android:textSize="15sp"
android:textColor="#ffffff"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:button="@drawable/chselector"
android:drawableLeft="@android:color/transparent"
android:focusable="false"
android:clickable="false"
android:padding="8dp"
/>
选择器 xml:
<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="@drawable/unchecked" android:state_checked="false"/>
<item android:drawable="@drawable/checked" android:state_checked="true"/>
<item android:drawable="@drawable/unchecked"/>
【问题讨论】:
标签: android android-layout android-fragments android-ui android-listfragment