[英]How to change the text view when an action occurs and have it displayed in front of the user
編輯:我想讓用戶點擊使整數值遞增1的按鈕。我也希望用戶能看到這種情況。 我不知道我必須使用什么代碼來更改文本視圖並使它顯示整數而不是字符串值。 我也願意將整數值更改為字符串值,然后顯示出來,但是我嘗試了這種方式,但不允許我更改字符串。 常規代碼可以更改XML。 如果仍然不清楚,請告訴我。 謝謝。
您的問題不是很清楚,如果您的意思是這(運行此活動),這是示例代碼:::
package com.hollow;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class HellowActivity extends Activity {
TextView textView;
Button button;
int incrementOnClick;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.button1);
textView = (TextView) findViewById(R.id.textView1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
textView.setText(""+incrementOnClick++);
}
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.