在Android的弹出窗口上更新textview时出错

问题描述 投票:0回答:1

我有一个简单的应用,每次单击该按钮都会更新数字。这在正常的活动上非常有效。

但是,现在我已经创建了一个弹出窗口,我想在里面做同样的事情,但是当单击弹出窗口内的按钮时,出现错误:

android.content.res.Resources$NotFoundException: String resource ID #0x1

当我尝试更新弹出窗口内的TextView时发生错误

这是我的简单代码,可以再次在正常的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

        }
    });



}}

有人可以帮我吗?

java android popupwindow
1个回答
0
投票

您的方法getReps()是返回整数值,因此您必须像下面那样设置文本

 repTextField.setText(String.valueFrom(the_workout_class.getReps()));  
 setsTextField.setText(String.valueFrom(the_workout_class.getReps())); 
© www.soinside.com 2019 - 2024. All rights reserved.