小编Sha*_*wat的帖子

不要连接用setText显示的文本.使用带占位符的资源字符串

我是android开发的新手,我想要setText一个数字,我正面临这个问题,并尝试了所有可能的方法来解决它.

请提供解决此问题的代码

代码如下:

public class GameActivity extends Activity implements View.OnClickListener{
    int correctAnswer;
    Button buttonObjectChoice1;
    Button buttonObjectChoice2;
    Button buttonObjectChoice3;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //here we initialize all our varibles
    int partA = 9;
    int partB = 2;
    correctAnswer = partA * partB;
    int wrongAnswer1 = correctAnswer - 1;
    int wrongAnswer2 = correctAnswer + 1;
    TextView textObjectPartA = (TextView)findViewById(R.id.textPartA);
    TextView textObjectPartB = (TextView)findViewById(R.id.textPartB);
    buttonObjectChoice1 = (Button)findViewById(R.id.buttonChoice1);
    buttonObjectChoice2 = (Button)findViewById(R.id.buttonChoice2);
    buttonObjectChoice3 = (Button)findViewById(R.id.buttonChoice3);
    textObjectPartA.setText("" + partA);
    textObjectPartB.setText("" …
Run Code Online (Sandbox Code Playgroud)

java android settext

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

java ×1

settext ×1