0

これは値を TextView に設定する私のコードです

enter code here

public void addHours(View view){
    final TextView mTextView = (TextView) findViewById(R.id.newHours_Value);
    String hourValue = R.id.enterHours.getText().toint();
    mTextView.setText("hourValue");
}

しかし、 R.id.enterHours.GetText() でエラーが発生します

プリミティブ型 int で getText() を呼び出せません

私は何を間違っていますか。

4

2 に答える 2

4

これ

 R.id.enterHours

を返しますint。そのため、 a を初期化するときは次のViewようにします

TextView mTextView = (TextView) findViewById(R.id.newHours_Value);

(TextView)それを にキャストするTextViewので、 のようにそのメソッドを呼び出すことができますgetText().toString()。したがって、おそらくあなたが望むのは

TextView hourValueTV = (TextView) findViewById*R.id.enterHours);  //assuming its a TextView and not EditText
String hourValue = hourValueTV.getText().toString();
于 2013-09-10T22:35:39.670 に答える
0

codeMagicが言ったことに追加:

この場合、値 (テキストを hourValue にしたい場合を除き、「hourValue」) ではなく、文字列の変数名 (参照) を使用してテキストを設定する必要があります。

そのはず

  mTextView.setText(hourValue);
于 2013-09-10T23:50:32.863 に答える