2015-11-05 63 views
-1

我想开发在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; 


     } 

    } 

} 

回答

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方法中

+0

大哥,你可以写一个代码为例...... – umr

+0

其tottaly你的逻辑。我应该怎么知道你想在按钮单击时执行什么操作 –

+0

我只能告诉你,你的按钮代码应该用onclick方法 –