Android - How to create clickable listview?

后端 未结 5 1262
心在旅途
心在旅途 2020-11-28 13:57

I want to make all my list items in the listview open up into a new page, so each listview item opens up onto a new black page that I can use. I don\'t know how to implement

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 14:30

    1. Inside fragment.java with Array Adapter

    String[] menuItems = {"Default C02", "Default 02 "};

        ListView listView = (ListView) root.findViewById(R.id.main_menu);
    
        ArrayAdapter listViewAdapter = new ArrayAdapter(
            getActivity()
            ,android.R.layout.simple_list_item_1
            ,menuItems
        );
    
        listView.setAdapter(listViewAdapter);
    
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            public void onItemClick(AdapterView l, View v, int position, long id){
                Log.i("menuItems", "You clicked Item: " + id + " at position:" + position);
    
    
    
            }
        });
    

提交回复
热议问题