2

点击项目在对话框内不起作用..

描述:我有一个打印按钮,当我单击该按钮时,将出现一个对话框,其中包含使用适配器的列表视图。当我单击列表视图行时,它必须转到其他活动。但问题是 onitemclick 在列表视图对话框中不起作用。

提前谢谢你。

WorkDetailView.java

 printbutton = (Button) findViewById(R.id.barcodePrintButton);
    printbutton.setOnClickListener(new OnClickListener() {
        private Context context = WorkDetailView.this;

        /**
         * 
         * Description: barcodePrintButton onClick to ServiceManager.callPrintService
         * 
         */
        @Override
        public void onClick(View view) {

                dialog = new Dialog(context);
                dialog.setContentView(R.layout.dialoglistview);
                dialog.setTitle("Print Dialog");

                listviewDialog = (ListView) dialog.findViewById(R.id.dialogList);
                dataDialogAdapter = new WorkDetailDialogAdapter(context, sampleDetailsArray);
                listviewDialog.setAdapter(dataDialogAdapter);
                listviewDialog.setClickable(true);
                listviewDialog.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
                    Log.i("selectedAdapter", "selectedAdapter"+ position);

                    Intent intent = new Intent("com.google.zxing.client.android.ENCODE");
                    intent.putExtra("ENCODE_DATA", patient.getMrnNumber());
                    intent.putExtra("ENCODE_FORMAT", "CODE_128");
                //  intent.putExtra("ENCODE_SHOW_CONTENTS", false);
                    startActivity(intent);
                    Toast.makeText(WorkDetailView.this, "Printing Barcode Result", Toast.LENGTH_LONG).show();

                }
            });

                dialog.show();
        }
    });
4

4 回答 4

1

您是否尝试将 onClickListener 的类型更改为 Dialog.onClickListener?

android.content.DialogInterface.OnClickListener ocl =   new Dialog.OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            // TODO Auto-generated method stub

        }
    };
于 2012-10-23T09:52:31.737 回答
0

放在dialog.show()前面listviewDialog.setClickable(true)

于 2012-10-23T09:10:12.347 回答
0

尝试这种方式来构建你的对话框

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.dialoglistview, 
    (ViewGroup) findViewById(R.id.root_id_in_dialoglistview_xml_tree));
dialog = AlertDialog.Builder(this).setTitle("Print Dialog").setView(layout);
于 2012-10-23T09:24:24.903 回答
0
Button btn=(Button)findViewById(R.id.button1);

        btn.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                showdialog();
            }});
private void showdialog() {
        listDialog = new Dialog(this);
        listDialog.setTitle("Select Item");
        LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = li.inflate(R.layout.list_view, null, false);
        listDialog.setContentView(v);
        listDialog.setCancelable(true);

        final ListView list1 = (ListView) listDialog.findViewById(R.id.listView1);
        String array[] = {"1","2","3"};

        ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.group, array);
        list1.setAdapter(adapt);
        listDialog.show();

        list1.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                System.out.println(position);
            }
        });
    }
于 2012-10-23T09:45:55.947 回答