简体   繁体   中英

Show text on button click

how to gradually display the text that is in the array by pressing one button

public class Array {

static final int[] lvl1_plot1= {
        R.string.plot1_1,
        R.string.plot1_2,
        R.string.plot1_3,
        R.string.plot1_4,


};

public class Level1plot1 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.level1_plot1);

    /**/
    Array array = new Array();
    /**/

    final TextView textView1 = (TextView)findViewById(R.id.textView1);
    final TextView textView2 = (TextView)findViewById(R.id.textView2);
    final TextView textView3 = (TextView)findViewById(R.id.textView3);
    final TextView textView4 = (TextView)findViewById(R.id.textView4);
    final ImageView imageView = (ImageView) findViewById(R.id.img);
    final Button skip = (Button) findViewById(R.id.skip);
    final Button button_continue = (Button) findViewById(R.id.button_continue);
    

    textView1.setText(array.lvl1_plot1[0]);

    button_continue.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            textView1.setText(array.lvl1_plot1[1]);

        }
    }); 

          

Try to use a TextSwitcher

btnNext.setOnClickListener(new View.OnClickListener() {
    public void onClick (View v) {
    
       currentIndex++;
       // If index reaches maximum reset it
       if (currentIndex == textToShow.length) {
          currentIndex = 0;
       }

       mSwitcher.setText(textToShow[currentIndex]);
}});

Follow the steps from the first answer in this link: Smooth text change in android animation

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