简体   繁体   English

如何为列表视图的每个列表项中的多个组件设置单击事件?

[英]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. 每个列表项目都包含一个按钮,现在我可以单击按钮,但我丢失了listitem点击。 This happens whenever i add a clickable component in with listitems. 每当我使用listitems添加可点击组件时,就会发生这种情况。 I have used custom adapter to achieve multiple components in listview. 我使用自定义适配器来实现listview中的多个组件。 I need both listitem click and button click how can i make it possible. 我需要listitem点击和按钮点击如何使它成为可能。

Here is my code(Click me) 这是我的代码(点击我)

Hi arun use this code I hope It was help you. 嗨arun使用此代码我希望它能帮到你。

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);
    }
    });

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. 因此,如果您需要将列表项包含的按钮的属性设置为false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Listview的List项目中为ListView设置OnItemClickListener事件 - How to set OnItemClickListener event for ListView in List item of Listview 如何在ListView项上为click事件设置侦听器 - How can I set a listener for a click event on a ListView item 如何通过单击每个按钮将多个项目添加到ListView - How to add multiple item to a ListView with each Button click 如何使用Android listview中的复选框处理列表视图项的单击事件? - How to handle click event for a list view item with checkbox in Android listview? 在listview Android的setOnItemClickListener上设置项目点击事件 - Set item click event on setOnItemClickListener of listview Android android在ListView项目中实现多次单击事件 - android implement multiple click event in ListView item 如何在列表视图的列表项中的图像视图上设置单击侦听器 - How to set a click listener on an image view in a list item of a listview 如何在ListView的项目上设置多次单击操作 - How to set multiple click actions on ListView's item 如何在listview项目中设置gridview并单击带有uniq posion的每个网格项目并单击evant - How to set gridview within listview item and click on each grid item with uniq posion and click evant Android:如何在ListView的列表项中为Button设置onClick事件 - Android : How to set onClick event for Button in List item of ListView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM