简体   繁体   English

发生动作时如何更改文本视图并将其显示在用户面前

[英]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.

相关问题 是否显示文字建议视图时如何收听 - How to listen when the text suggestion view is displayed or not 如何在新用户登录时更改文本视图? - How to change the text view when a new user is logged in? Android Espresso:当视图显示在屏幕上时如何执行操作? - Android Espresso : How to perform an action when the view is displayed on the screen? 用户滚动时文本视图发生变化 - Text view change when user scroll 根据显示的文本更改按钮的动作 - Change action of a button according to text displayed 如何在用户更改/刷卡页面时更改视图寻呼机中的页面? - How to change page in view pager when user change/swipe page? 将textview与arraylist链接,并在事件发生时更改文本 - Linking a textview with an arraylist and change text when event occurs 制作动画时如何将视图置于最前面? - How to bring a view to front when doing animation? 如何更改操作栏上的文本 - How to change the text on the action bar 如何根据用户在上方的文本视图中输入的内容来更改文本视图的位置? - How can I make a Text View change it's position based on what the user puts in the Text View above?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM