onitemclick在listview对话框中不起作用

时间:2012-10-23 08:47:46

标签: android android-layout android-intent android-emulator android-listview

单击项目上的

在对话框中不起作用..

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

提前谢谢你。

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 个答案:

答案 0 :(得分: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

        }
    };

答案 1 :(得分:0)

dialog.show()

之前放置listviewDialog.setClickable(true)

答案 2 :(得分: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);

答案 3 :(得分: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);
            }
        });
    }