在按钮上显示文字单击

发布于 2025-01-24 19:34:08 字数 1226 浏览 2 评论 0原文

如何通过按下一个按钮

公共类数组{

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


};

public class calle1plot1扩展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]);

        }
    }); 

          

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]);

        }
    }); 

          

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红墙和绿瓦 2025-01-31 19:34:08

尝试使用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]);
}});

遵循此链接中第一个答案的步骤:平滑的文本更改Android动画

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文