0

我正在使用以下代码。但是警报对话框关闭没有发生。我正在使用具有列表视图的自定义视图,我正在尝试单击列表项,警报对话框应该被关闭。在项目上单击侦听器正在工作,但警报对话框没有关闭。任何机构都可以帮助我。

View titleView = new View(MixContainerInfoActivity.this);
    titleView = (View)getLayoutInflater().inflate(R.layout.custom_unit_title, null);
    TextView tv = (TextView)titleView.findViewById(R.id.custom_title_txt_view);     
    tv.setTypeface(typeFace);
    tv.setText("CONTAINER OR IMPLEMENT...");

    View view = new View(MixContainerInfoActivity.this);
    view = (View)getLayoutInflater().inflate(R.layout.unit_list, null);
    containerList = (ListView)view.findViewById(R.id.unit_list_view);
    ArrayAdapter<Vector> containerAdapter = new UnitMenuAdapter(MixContainerInfoActivity.this, R.layout.custom_unit_list, containerVector);     
    containerList.setAdapter(containerAdapter);


     final AlertDialog.Builder builder = new AlertDialog.Builder(MixContainerInfoActivity.this);

     builder.setCustomTitle(titleView);
     builder.setView(view);



     final AlertDialog alert = builder.create();
     alert.show(); //edited here

     containerList.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                System.out.println("Item Clicked..");

                alert.dismiss();

            }
        });
4

2 回答 2

2

试试这个,让我知道会发生什么,

AlertDialog.Builder builder = new AlertDialog.Builder(MixContainerInfoActivity.this);
View view = new View(MixContainerInfoActivity.this);
view = (View)getLayoutInflater().inflate(R.layout.unit_list, null);
builder.setCustomTitle(titleView);
builder.setView(view);
containerList = (ListView)view.findViewById(R.id.unit_list_view);
ArrayAdapter<Vector> containerAdapter = new UnitMenuAdapter(MixContainerInfoActivity.this, R.layout.custom_unit_list, containerVector);     
containerList.setAdapter(containerAdapter);
final AlertDialog alert = builder.create();
alert.show();

containerList.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                System.out.println("Item Clicked..");
                alert.dismiss();
            }
        });
于 2012-04-19T09:30:35.393 回答
0

单击列表中的项目时会引发setOnItemClickListener。由于对话框显示在列表上方,因此您无法单击列表的项目。相反,您应该将以下行添加到您的构建器并删除setOnItemClickListener

//it will dismiss the dialog automatically
builder.setNegativeButton("OK", null);
于 2012-04-19T09:20:41.640 回答