Custom ListView in a dialog

前端 未结 2 1996
小鲜肉
小鲜肉 2021-01-20 17:43

i have a list view , inside this list when click on an item of it ,it will show a custom list inside a dialog box

the dialog shows up but its only shows the title

2条回答
  •  旧时难觅i
    2021-01-20 18:29

    @Vishal is right, you needs to use AlertDialog if you needs to inflate view inside your dialog. Here's the example code. Tried the code below.

    public void showDialog(){
        AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());     
        dialog.setTitle("List of likers");
        dialog.setCancelable(true);
    
        View view = ((Activity)getContext()).getLayoutInflater().inflate(R.layout.likers_list, null); 
    
        dbobj = new DataBaseHandler(getContext());
        likeItems=dbobj.select_HowlikeComment();
        dbobj.CloseDataBase();
    
    
        ListView list = (ListView) view.findViewById(R.id.ListLikersList);
        LikersCustomeAdapter adapter= new LikersCustomeAdapter(getContext(), R.layout.likerscustomelist, likeItems);
    
        list.setAdapter(adapter);
    
        dialog.setView(view);
        dialog.show();
    }
    

提交回复
热议问题