Android - Executing a custom listview in a custom dialog properly

前端 未结 1 426
-上瘾入骨i
-上瘾入骨i 2020-12-14 21:14

I have an application where I would want to display a custom list view consisting of two textViews inside a custom dialog box in android. So far, I\'m having a difficult tim

相关标签:
1条回答
  • 2020-12-14 22:06

    Are you doing the following? You will need to inflate the layout file dialog_main, find the ListView, set an adapter and an OnItemClickListener for it. After this, you can use the dialog's setContentView(View) method to get the list to display.

    private void showDialog(){
    
        final Dialog dialog = new Dialog(this);
    
        View view = getLayoutInflater().inflate(R.layout.dialog_main, null);
    
        ListView lv = (ListView) view.findViewById(R.id.custom_list);
    
        // Change MyActivity.this and myListOfItems to your own values
        CustomListAdapterDialog clad = new CustomListAdapterDialog(MyActivity.this, myListOfItems);
    
        lv.setAdapter(clad);
    
        lv.setOnItemClickListener(........);
    
        dialog.setContentView(view);
    
        dialog.show();
    
    }
    

    By the way, your adapter looks alright. It isn't working because you're not giving it anything to work on.

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