导航按钮没有响应

时间:2015-11-05 17:56:36

标签: android button navigation

我正在尝试在android studio中开发一个测验应用程序,并且我的导航按钮面临问题...... 我的下一个和后面的导航按钮不起作用,我错过了什么... 下面是我在java类中使用的代码... 请指出我出错的地方以及你建议纠正的地方......

public class MC_questions extends AppCompatActivity implements View.OnClickListener {
    TextView tvquestions, tvanswers, tvtotallength_yy, tvpresentindex_xx;

    Button bback, bshowanswer, bnext;


    String[] mc_questions, mc_answers;

    int index;

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





///initialization of text view
        tvquestions = (TextView) findViewById(R.id.tvquestions);
        tvanswers = (TextView) findViewById(R.id.tvanswer);
        tvtotallength_yy = (TextView) findViewById(R.id.tvyy);
        tvpresentindex_xx = (TextView) findViewById(R.id.tvxx);

///initialization of buttons
        bback = (Button) findViewById(R.id.bback);
        bshowanswer = (Button) findViewById(R.id.bshowanswer);
        bnext = (Button) findViewById(R.id.bnext);

///importing the string array from values folder
        mc_questions = getResources().getStringArray(R.array.mc_questions);
        mc_answers = getResources().getStringArray(R.array.mc_answers);

///onclick listener for 3 buttons
        bback.setOnClickListener(this);
        bshowanswer.setOnClickListener(this);
        bnext.setOnClickListener(this);


///Setting values to our variables and 4 TextViews
        index = 0;
        tvquestions.setText(mc_questions[index]);
        tvanswers.setText("Press \"Show Answer\" Button for Answer");
        tvpresentindex_xx.setText (String.valueOf(index+1));
        tvtotallength_yy.setText(String.valueOf(mc_questions.length));



    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.bback:


                break;

            case R.id.bshowanswer:


                break;

            case R.id.bnext:


                break;


        }

    }

}

1 个答案:

答案 0 :(得分:0)

根据onClick方法中的按钮单击将代码放入内部

@Override
        public void onClick(View v) {

            switch (v.getId()) {
                case R.id.bback:

    //write a code here that you want to execute when this button is presssed
                    break;

                case R.id.bshowanswer:

    //write a code here that you want to execute when this button is presssed
                    break;

                case R.id.bnext:
    //write a code here that you want to execute when this button is presssed

                    break;


            }

        }
  

我的导航按钮就像下一个和后一个不起作用

因为您没有在onClick方法

中添加任何代码