创建一个对话框

时间:2014-03-12 16:32:33

标签: java android eclipse zxing

您好我是Java编程的新手,并决定在我的应用程序中包含Zxing条形码扫描器。基本上我想要在单击按钮时显示一个对话框,其中包括两个按钮。一个下载应用程序另一个继续(打开应用程序)如果已经下载了应用程序。我似乎无法让它发挥作用。

这是我当前的代码,其中包含两个按钮。继续按钮应该通过下载,而是自动打开另一个应用程序。 QRscanner类:

公共类Qrscanner扩展了Activity

{
    final Context context = this;
    ImageButton imageButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.qrscanner);

        imageButton = (ImageButton) findViewById(R.id.butQR);

        imageButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                context);

            // set title
            alertDialogBuilder.setTitle("Do you have Zxing downloaded?");

            // set dialog message
            alertDialogBuilder
                .setMessage("Press download to download zxing barcode scanner, if you have zxing downloaded press Continue")
                .setCancelable(false)
                .setPositiveButton("Download",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=com.google.zxing.client.android")));
                    }
                  })
                .setNegativeButton("Continue",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {


                        dialog.cancel();
                    }
                });

                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();
            }
        });
    }

代码用于检查您是否已拥有该应用程序并在以下情况下打开该应用程序:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.qrscanner);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.qrscanner);

        HandleClick hc = new HandleClick();

        findViewById(R.id.butQR).setOnClickListener(hc);

      }

      private class HandleClick implements OnClickListener{


        public void onClick(View arg0) {

          Intent intent = new Intent("com.google.zxing.client.android.SCAN");

          switch(arg0.getId()){

            case R.id.butQR:

              intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

            break;


          }
          startActivityForResult(intent, 0);    //Barcode Scanner to scan for us
        }
      }
      public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {

          if (resultCode == RESULT_OK) {

          } else if (resultCode == RESULT_CANCELED) {

          }
        }
      }



}

提前致谢

0 个答案:

没有答案