ListView with OnItemClickListner android?


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

Step 1: now set onItemClickListner inside onCreate method

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

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