【发布时间】:2017-05-25 09:00:27
【问题描述】:
这是堆栈代码; 单击按钮时,按钮编号被添加到堆栈中,并在 textview 上显示推送,类似地,单击时,推送编号从堆栈中推送。但只完成一次操作或交替,我不能推两次。
Button b1 = (Button) findViewById(R.id.btn1);
b1.setOnClickListener(this);
Button b2 = (Button) findViewById(R.id.btn2);
b2.setOnClickListener(this);
EditText e1 = (EditText) findViewById(R.id.etn1);
x = e1.getId();
// 点击事件监听器
@Override
public void onClick(View v) {
TextView t1 = (TextView) findViewById(R.id.tvn);
if (v.getId()== R.id.btn1) {
Stack s1 = new Stack();
s1.push(x);
EditText e1 = (EditText) findViewById(R.id.etn1);
e1.setId(0);
t1.setText("Pushed");
t1.setAnimation(AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left));
}
else if (v.getId() == R.id.btn2) {
Stack s2 = new Stack();
s2.pop();
t1.setText("Poped");
t1.setAnimation(AnimationUtils.loadAnimation(MainActivity.this,
android.R.anim.slide_in_left));
}
}
【问题讨论】:
-
如果你给我们堆栈跟踪,你会帮助我们
-
在 onCreateMethod 中初始化视图