jeudi 23 avril 2015

setOnChildClickListener of ExpandableListView inside a Custom Alter dialog does not work

I have created a custom Alert Dialog with a ExpandableListView inside it. The ExpandableListView childs are Checkboxes.

I am trying to set the event listener whenever the user clicks on one of the checkboxes but it does not work. I can select and unselect the checkboxes in the custom alert dialog but the event handler does not work. Can anyone help me?

Code to create the alert dialog

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://ift.tt/nIICcg"
      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>

I have tried with the android:focusable and without it and it did not work.




Aucun commentaire:

Enregistrer un commentaire