繁体   English   中英

收缩视图并膨胀另一个

[英]deflate view and inflate another

按下我的“下一步”按钮,我有一个通过字符串数组的语音气泡。 在所有项目完成显示并且用户再次单击“下一步”按钮后,我想要缩小当前子视图并使新视图膨胀。 现在它在字符串数组完成显示“下一步”按钮的多次点击后崩溃。 我怎样才能让它发挥作用?

    package com.jibushi;

    import android.app.Activity;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.TextView;

    public class LessonsShell extends Activity{
    private static final int MESSAGE_SHOW_POPUP = 1;
    private static final int MESSAGE_SHOW_POPUP2 = 1;
    private static final long TIME_DELAY = 1000;//1 seconds
    private static final long TIME_DELAY2 = 500;
    private View view;
    private View view2;

    private int count = 0;
    private TextView lessonsDialog;
    private String[] myIntroString;

    private Handler handler = new Handler() {
       public void handleMessage(Message msg) {
          switch(msg.what) {
            case MESSAGE_SHOW_POPUP:
               view();
               break;
           }
       };
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

    setContentView(R.layout.lessons);
    //this will send a message to the handler to display the popup after 1 seconds.
    handler.sendEmptyMessageDelayed(MESSAGE_SHOW_POPUP,TIME_DELAY);

    }

    private void view() {
    // TODO Auto-generated method stub
    ViewGroup parent = (ViewGroup) findViewById(R.id.lessons_bg);
     view = LayoutInflater.from(getBaseContext()).inflate(R.layout.lessons_dialog, null);
     parent.addView(view);

     lessonsDialog = (TextView) findViewById(R.id.lessonsDialog);

     Resources res = getResources();
     myIntroString = res.getStringArray(R.array.lessons_dialog_array); 

     Button nextButton = (Button) findViewById(R.id.next_button);
     nextButton.setOnClickListener(new View.OnClickListener() {
         public void onClick(View view) {
             if (count < myIntroString.length) {
                 lessonsDialog.setText(myIntroString[count]);
                 count++;
             } else {
                 if (myIntroString[-1] != null) {
                     handler2.sendEmptyMessageDelayed(MESSAGE_SHOW_POPUP2, TIME_DELAY2);
                 }
             }
         }
     });

    }

    private Handler handler2 = new Handler() {
           public void handleMessage(Message msg) {
              switch(msg.what) {
                case MESSAGE_SHOW_POPUP2:
                   view2();
                   break;
               }
           }

        private void view2() {
            // TODO Auto-generated method stub
             ViewGroup parent = (ViewGroup) findViewById(R.id.lessons_bg);
             view2 = LayoutInflater.from(getBaseContext()).inflate(R.layout.lessons_start, null);
             parent.addView(view2); 
             parent.removeView(view);
        };
        };
    }

啊,是的,我现在看到了。 你不能这样做:

 myString[-1]

索引-1在数组中不存在。 你想做什么? 也许myString[count - 1]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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