添加按钮更多按钮

时间:2014-05-27 07:41:39

标签: java android sdk

我试图放的不仅仅是按钮,但它不起作用:

    View scanbarcode = (Button) findViewById(R.id.scanbarcode);
    View facility = (Button) findViewById(R.id.facility);   

    // For Scan bar code
    scanbarcode.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent(getBaseContext(), CameraPreviewActivity.class);
                        startActivity(intent);   

        }

    });

    // For facility menu 
    facility.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(getBaseContext(), FacilityActivity.class);
                        startActivity(intent);   
        }
    });

1 个答案:

答案 0 :(得分:1)

不是真正的答案,但我必须展示代码。如果您将View更改为Button,那该怎么办?

       Button scanbarcode = (Button) findViewById(R.id.scanbarcode);
       Button facility = (Button) findViewById(R.id.facility);   

       // For Scan bar code
      scanbarcode.setOnClickListener(new OnClickListener() {
           @Override
           public void onClick(View arg0) {

           Intent intent = new Intent(getBaseContext(),CameraPreviewActivity.class);
                 startActivity(intent);   

         }

           });

       // For facility menu 
         facility.setOnClickListener(new OnClickListener() {
        @Override
         public void onClick(View arg0) {
       Intent intent = new Intent(getBaseContext(), FacilityActivity.class);
                startActivity(intent);   
    }
  });

这应该有用......另外,你真的将Buttons引用到了正确的layout.xml吗?你能告诉我们layout.xml文件吗?

相关问题