0 works

ListView with OnItemClickListner android?


dashboard

Posted by @Awais malik #android #java

Step 0: First populate your list with items

    private ArrayList<String> arrayList;
    ListAdapter listAdapter;

   String[] array = new String[5];
                array[0] = "optn 1";
                array[1] = "optn 2";
                array[2] = "optn 3";
// in on create method

        arrayList = new ArrayList<>();
        listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1 , array);
        mAvailableProfilesList.setAdapter(listAdapter);
        
content_copyCopy to Clipboard

Step 1: now set onItemClickListner inside onCreate method

 mAvailableProfilesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 
                                Toast.makeText(ProfileMaking.this , "clicked "+array[position] , Toast.LENGTH_SHORT).show();
   }
        });
content_copyCopy to Clipboard

in this tutorial i will teach you how to set onItemClickListener on a listView

,

>> Browse more code snippets

more_vert