[英]How to change the text view when an action occurs and have it displayed in front of the user
Edit: I would like for the user to hit a button that causes an integer value to increase incrementally by 1. I would also like for the user to see this as it is happening. 编辑:我想让用户点击使整数值递增1的按钮。我也希望用户能看到这种情况。 I do not know what code I have to use to change the text view and make it show an integer rather than a string value. 我不知道我必须使用什么代码来更改文本视图并使它显示整数而不是字符串值。 I would also be up for changing an integer value into a string value and then have it displayed, but i tried this one way and it would not allow me to change the string. 我也愿意将整数值更改为字符串值,然后显示出来,但是我尝试了这种方式,但不允许我更改字符串。 Can the regular code change the XML. 常规代码可以更改XML。 If still not clear let me know please. 如果仍然不清楚,请告诉我。 Thank you. 谢谢。
Ur question is not so clear, here is a sample code if thats what u mean (Run this activity)::: 您的问题不是很清楚,如果您的意思是这(运行此活动),这是示例代码:::
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.