Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a button that is meant to swap from one activity to another which use to work but ever since i added the coding for another button to call for zxing's scanning feature the button no longer does anything at all. This is my MainActivity.java for those who are willing to help

 package com.example.mdpmk1;

    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.content.Context;
    import android.net.wifi.ScanResult;
    import android.widget.Button;
    import com.google.zxing.integration.android.IntentIntegrator;
    import com.google.zxing.integration.android.IntentResult;

    public class MainActivity extends Activity {

    Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();
    }

    public void addListenerOnButton() {

        final Context context = this;


        button = (Button) findViewById(R.id.scan);


        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if(v.getId()==R.id.scan){
                //scan

                    IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
                    integrator.initiateScan();
                }


            }

        });

    }


    public void onActivityResult(int requestCode, int resultCode, Intent intent) 
    {
        //super.onActivityResult(requestCode, resultCode, intent);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {

            } else if (resultCode == RESULT_CANCELED) {

            }
        }
    }





    Button button2;

    public void onCreate1(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();
    }

    public void addListenerOnButton1() {

        final Context context = this;


        button2 = (Button) findViewById(R.id.getResults);


        button2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, ScanResult.class);
                startActivity(intent);



            }

        });

    }


    }

The button that isn't responding is button2 so if you can help me with anything that would be lovely, Thanks in advance. All help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

For both buttons You are adding Same Listener

addListenerOnButton();

addListenerOnButton1();

please change in button2 accordingly


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...