简体   繁体   中英

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. 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. 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++);    
        }
    });
}
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM