Creating a Dialog after an onClick event

后端 未结 4 930
梦如初夏
梦如初夏 2021-01-27 18:26

Hi i am working the first time with dialogs. i want to create a dialog after an item in a listView was clicked:

    String[] listItems = {\"Colour\", \"Font Size         


        
4条回答
  •  一个人的身影
    2021-01-27 19:01

    try this one

    String[] listItems = {"Colour", "Font Size",};
    ListView lv = (ListView) findViewById(R.id.settings_list);
    
    lv.setAdapter(new ArrayAdapter
    (this, android.R.layout.simple_list_item_1, listItems));
    
    lv.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView parent, View
                view, int position, long id)
        {
            String[] listItems = {"Colour", "Font Size",};
            if(listItems[position].equals("Font Size"))
            {
    
    
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                getApplicationContext());
    
                // set title
                alertDialogBuilder.setTitle("Choose Font Size");
    
                //create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
    
                // show it
                alertDialog.show();
    
            }
    
        }
    });
    

提交回复
热议问题