簡體   English   中英

在 Android 上的彈出窗口上更新 textview 時出錯

[英]Error while updating textview on popup window on Android

我有一個簡單的應用程序,每次單擊按鈕時都會更新數字。 這對正常的活動非常有效。

但是,現在我制作了一個彈出窗口,我想在里面做同樣的事情,但是當點擊彈出窗口內的按鈕時,我收到錯誤:

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

當我嘗試更新彈出窗口內的 TextView 時發生錯誤

這是我的簡單代碼,它再次在正常活動上完美運行:

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

        }
    });



}}

有人可以幫我嗎?

您的方法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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM