我已经在其中创建了一个自定义警报对话框,其中包含ExpandableListView。 ExpandableListView子项是复选框。
我试图在用户点击其中一个复选框时设置事件监听器,但它不起作用。我可以在自定义警报对话框中选中和取消选中复选框,但事件处理程序不起作用。任何人都可以帮助我吗?
创建警告对话框的代码
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select the route or segments");
LinearLayout layout = (LinearLayout) findViewById(R.id.custom_alert_dialog);
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.custom_alert_dialog_routes, null);
ExpandableListView listView = (ExpandableListView) dialoglayout.findViewById(R.id.routesListView);
ExpandableListAdapter listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
listView.setAdapter(listAdapter);
listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Toast.makeText(getApplicationContext(), "Clicked the checkbox", Toast.LENGTH_LONG).show();
Log.d("Click", "I have clicked a checkbox.");
return false;
}
});
builder.setView(dialoglayout);
builder.setInverseBackgroundForced(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="@+id/expandedListItem"
android:textColor="#000000"
android:focusable="false"
android:layout_marginLeft="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"/>
</LinearLayout>
我尝试过使用android:focusable而没有它,但它没有用。
答案 0 :(得分:0)
尝试使用setOnItemClickListener
代替setOnChildClickListener
。