arnp
arnp

Reputation: 3208

How to set click event for multiple components in each list item of a listview?

I am using a listview with mulitple list items. Each list items contain a button now i am able to click the buttons but i lost the listitem click. This happens whenever i add a clickable component in with listitems. I have used custom adapter to achieve multiple components in listview. I need both listitem click and button click how can i make it possible.

Here is my code(Click me)

Upvotes: 0

Views: 965

Answers (2)

Maneesh
Maneesh

Reputation: 6128

If any element in the list item layout is focusable then it is not possible to click both on list item and that button. Then list item click will not happen. To make both work then make sure that all the elements in the list item layout should not be focusable. So if you need to set the property of the button contained by the list item to be false.

Upvotes: 0

Nik88
Nik88

Reputation: 1022

Hi arun use this code I hope It was help you.

ListView lv1 = getListView();
    lv1.setTextFilterEnabled(true);
    lv1.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
       MySlammerCustomAdapter adapter1 = (MySlammerCustomAdapter) parent.getAdapter();
       String slambook_id = adapter1.getItem(position).toString();
       // Toast.makeText(getApplicationContext(), user_id, Toast.LENGTH_SHORT).show();
       finish();
       intent = new Intent(MySlammerActivity.this, SlamBookInfoViewActivity.class);
       intent.putExtra("KeyUser_id", slambook_id);
       startActivity(intent);
    }
    });

Upvotes: 2

Related Questions