0
我的佈局上有4個按鈕。一個是「正確答案」,另外三個是「錯誤答案」 我已經編寫了一個用於我的錯誤答案的常用方法,但代碼要求我在該段代碼中推送不同的按鈕名稱。我如何管理?Android代碼:如何在方法之間傳遞相同活動中的變量
這是我的代碼
/* call method for a answer */
final Button rredButton=(Button)findViewById(R.id.RredButton);
rredButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupright, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnNxtScr = (Button)popupView.findViewById(R.id.nextscreen);
btnNxtScr.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
Intent myintent1 = new Intent(colorActivity.this,LearningTimeMenu.class);
startActivity(myintent1);
}
});
popupWindow.showAsDropDown(rredButton, 50, -300);
}});
我試圖做此
final Button rblueButton=(Button)findViewById(R.id.RblueButton);
rblueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
createWrongPop();
}});
並在createWrongPop定義碼的佈局充氣部分()方法;但是這行代碼 popupWindow.showAsDropDown(rredButton,50,-330)期望每個3按鈕的按鈕ID。
如何將每個變量傳遞給該方法?