[英]Error while updating textview on popup window on Android
I have an simple app which updates number each time the button is clicked.我有一个简单的应用程序,每次单击按钮时都会更新数字。 This works perfectly on a normal Activity.这对正常的活动非常有效。
However, now I have made an popup window which I want to do the same inside, but when the button inside the popup window is clicked, I get the error:但是,现在我制作了一个弹出窗口,我想在里面做同样的事情,但是当点击弹出窗口内的按钮时,我收到错误:
android.content.res.Resources$NotFoundException: String resource ID #0x1
The error occurs when I try to update the TextView inside the popup window当我尝试更新弹出窗口内的 TextView 时发生错误
Here is my simple code which again works perfectly on a normal Activity:这是我的简单代码,它再次在正常活动上完美运行:
public class PopActivity extends Activity {
private WorkOutClass the_workout_class = new WorkOutClass();
private TextView repTextField, setsTextField;
private Button den_knappen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pop);
repTextField = (TextView) findViewById(R.id.repetitionID);
setsTextField = (TextView) findViewById(R.id.setsID);
den_knappen = (Button) findViewById(R.id.buttonID);
repTextField.setText("" + the_workout_class.getReps());
setsTextField.setText(""+ the_workout_class.getSets());
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int)(width*.8), (int)(height*.7));
WindowManager.LayoutParams params = getWindow().getAttributes();
params.gravity = Gravity.CENTER;
params.x = 0;
params.y = 20;
getWindow().setAttributes(params);
den_knappen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
the_workout_class.increaseReps();
repTextField.setText(the_workout_class.getReps()); // Normally this works perfectly, but here i get ERROR
setsTextField.setText(the_workout_class.getReps()); // Normally this works perfectly, but here i get ERROR
}
});
}}
Could someone help me please?有人可以帮我吗?
your method getReps()
is return integer value so you have to set text like below您的方法getReps()
返回整数值,因此您必须设置如下文本
repTextField.setText(String.valueFrom(the_workout_class.getReps()));
setsTextField.setText(String.valueFrom(the_workout_class.getReps()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.