Android list view setOnItemClickListener not working

前端 未结 4 860
执念已碎
执念已碎 2021-01-13 06:04

I want to hide the edit text and button field initially in list view and show that edit text and button for a particular raw in list view when that raw is clicked.So I tried

相关标签:
4条回答
  • 2021-01-13 06:17

    In my Case setOnItemClickListener works fine in Android Versions Upto 5.1.1 But Having On Android 6.0.1. At last I found the solution Try this
    Remove these Lines from Your XML Layout

    android:orientation="vertical"
    tools:context=".ManageRequest"
    android:contextClickable="true"
    

    Works for Me in Android Version 6.0.1 Hope Your Problems Solved ..!!! Happy Coding :)

    0 讨论(0)
  • 2021-01-13 06:23

    Add the following attributes to your button

      android:focusable="false"
      android:focusableInTouchMode="false"
    

    ListView setOnItemClickListener not working by adding button

    Is your edittext taking focus on click of list item? If so remove the focus on edittext also.

    0 讨论(0)
  • 2021-01-13 06:26
    // try this
    public class MainPortal extends Activity {
        private List<Employee> employees = new ArrayList<Employee>();
        EditText et;
        ListView list;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main_portal);
            populateEmployeeList();
            //populsteListView();
    
            list = (ListView) findViewById(R.id.employeeListView);
            ArrayAdapter<Employee> adapter = new MylistAdapter();
            list.setAdapter(adapter);
    
            list.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
    //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING
                    Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
    
    0 讨论(0)
  • 2021-01-13 06:29

    Here your edittext inside the listview is having all the focus, so this listview onClick is not working. Remove the focus from the editext box and it will start working

    0 讨论(0)
提交回复
热议问题