字符串数组完成后开始一个新视图

时间:2011-11-26 05:02:15

标签: android android-widget

所以,我有这个“next”按钮调用一个字符串数组,当count到达“-1”时,我想开始一个新的视图。我怎么能这样做?

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

3 个答案:

答案 0 :(得分:1)

可能你想开始新的活动。

Intent intent = new Intent(getApplicationContext(), YourClassName.class);
startActivity(intent);

答案 1 :(得分:1)

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewName = inflater.inflate(R.layout.YOUR_VIEW_ID, null, false);

使用方法addView(View child)和removeView(View view)来添加和删除视图。

答案 2 :(得分:1)

Нou可以调用removeView(View child);和addView(View child);在ViewGroup上。

示例

LinearLayout viewHolder = (Linearlayout) findViewById(R.id.view_holder);

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View viewBeforeClick = inflater.inflate(R.layout.YOUR_VIEW_ID1, null, false);
View viewAfterClick = inflater.inflate(R.layout.YOUR_VIEW_ID2, null, false);

viewHolder.addView(viewBeforeClick);

//when clicked on next button

viewHolder.removeView(viewBeforeClick);
viewHolder.addView(viewAfterClick);