鉴于放气膨胀和另一 [英] deflate view and inflate another
本文介绍了鉴于放气膨胀和另一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的下一步按钮的preSS我必须通过一个字符串数组语音泡运行。在所有的项目完成,并显示在用户点击下一步按钮一次,我想紧缩当前子视图和膨胀的新观点。现在它崩溃的字符串数组完成显示下一步按钮,多个clickings后。
我怎样才能得到这个工作?
包com.jibushi; 进口android.app.Activity;
进口android.content.res.Resources;
进口android.os.Bundle;
进口android.os.Handler;
进口android.os.Message;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.Button;
进口android.widget.TextView; 公共类LessonsShell延伸活动{
私有静态最终诠释MESSAGE_SHOW_POPUP = 1;
私有静态最终诠释MESSAGE_SHOW_POPUP2 = 1;
私有静态最后长TIME_DELAY = 1000; //1秒
私有静态最后长TIME_DELAY2 = 500;
私人浏览视图。
私人浏览视图2; 私人诠释计数= 0;
私人TextView的lessonsDialog;
私有String [] myIntroString; 私人处理程序处理程序=新的处理程序(){
公共无效的handleMessage(消息MSG){
开关(msg.what){
案例MESSAGE_SHOW_POPUP:
视图();
打破;
}
};
}; @覆盖
保护无效的onCreate(捆绑savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState); 的setContentView(R.layout.lessons);
//这将消息发送给处理器1秒后显示弹出。
handler.sendEmptyMessageDelayed(MESSAGE_SHOW_POPUP,TIME_DELAY); } 私人无效视图(){
// TODO自动生成方法存根
ViewGroup中父=(ViewGroup中)findViewById(R.id.lessons_bg);
鉴于= LayoutInflater.from(getBaseContext())膨胀(R.layout.lessons_dialog,NULL);
parent.addView(视图); lessonsDialog =(的TextView)findViewById(R.id.lessonsDialog); 资源解析度= getResources();
myIntroString = res.getStringArray(R.array.lessons_dialog_array); 按钮Next按钮=(按钮)findViewById(R.id.next_button);
nextButton.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(查看视图){
如果(计数< myIntroString.length){
(myIntroString [计数])lessonsDialog.setText;
算上++;
}其他{
如果(myIntroString [-1]!= NULL){
handler2.sendEmptyMessageDelayed(MESSAGE_SHOW_POPUP2,TIME_DELAY2);
}
}
}
}); } 私人处理程序handler2 =新的处理程序(){
公共无效的handleMessage(消息MSG){
开关(msg.what){
案例MESSAGE_SHOW_POPUP2:
视图2();
打破;
}
} 私人无效视图2(){
// TODO自动生成方法存根
ViewGroup中父=(ViewGroup中)findViewById(R.id.lessons_bg);
视图2 = LayoutInflater.from(getBaseContext())膨胀(R.layout.lessons_start,NULL);
parent.addView(视图2);
parent.removeView(视图);
};
};
}
解决方案
啊,是的,我现在看到了。你可以这样做:
的myString [-1]
的索引-1阵列不存在。你想做什么?也许的myString [数 - 1]?
on the press of my "next" button I have a speech bubble run through a string array. After all the items finish displaying and the user clicks the "next" button once more I would like to deflate the current child view and inflate a new view. Right now it crashes after the string array finishes displaying on multiple clickings of the "next" button. How can I get this to work?
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);
};
};
}
解决方案
Ah, yes, I see it now. You can't do this:
myString[-1]
The index -1 does not exist in arrays. What are you trying to do? Perhaps myString[count - 1]
?
这篇关于鉴于放气膨胀和另一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文