且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android - 在自定义对话框中正确执行自定义列表视图

更新时间:2022-05-20 02:57:09

你在做以下事情吗?您将需要扩充布局文件 dialog_main,找到 ListView,为其设置适配器和 OnItemClickListener.在此之后,您可以使用对话框的 setContentView(View) 方法来获取要显示的列表.

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.