android 选项卡跳转问题 androideclipse开发工具tabhost 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 额,你贴下logcat日志呗,,, 好的,非常感谢你try { String uName=staticContent.uName;//获取用户名 //设置标题 TextView tvtitle=(TextView)findViewById(R.id.title); tvtitle.setText("工单处理"); //设置显示用户名 TextView tvuname=(TextView)findViewById(R.id.txtUname); tvuname.setText(uName); group = (RadioGroup)findViewById(R.id.main_radio); tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec(TAB_HOME) .setIndicator(TAB_HOME) .setContent(new Intent(this,Gddaichuli.class))); //.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)这句是选项卡切换刷新 tabHost.addTab(tabHost.newTabSpec(TAB_MES) .setIndicator(TAB_MES) .setContent(new Intent(this,MainActivity.class))); tabHost.addTab(tabHost.newTabSpec(TAB_TOUCH) .setIndicator(TAB_TOUCH) .setContent(new Intent(this,Gdhuidan.class))); group.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radio_button0: tabHost.setCurrentTabByTag(TAB_HOME); break; case R.id.radio_button1: tabHost.setCurrentTabByTag(TAB_MES); break; case R.id.radio_button2: tabHost.setCurrentTabByTag(TAB_TOUCH); break; default: break; } } }); } catch (Exception e) { // TODO: handle exception String error=e.toString(); Dialog alertDialog = new AlertDialog.Builder(this). setTitle("1"). setMessage(error). setIcon(R.drawable.nt2). create(); alertDialog.show(); } } Gddaichuli.java页面代码try { Uname=staticContent.LoginName; //启动数据加载动画 showRoundProcessDialog(R.layout.loaddata); newthread=new Thread(daichuli); newthread.start(); } catch (Exception e) { // TODO: handle exception String error=e.toString(); Dialog alertDialog = new AlertDialog.Builder(this). setTitle("对话框的标题"). setMessage(error). setIcon(R.drawable.nt2). create(); alertDialog.show(); } } final Handler h=new Handler(){ @Override public void handleMessage(Message msg){ super.handleMessage(msg); if(msg.what==0) { mDialog.dismiss();//关闭数据加载动画 Toast.makeText(getApplicationContext(),"没有数据",Toast.LENGTH_LONG).show(); } if(msg.what==1) { ArrayList result=new ArrayList(); result=(ArrayList) msg.obj; //绑定Layout里面的ListView final ListView list = (ListView) findViewById(R.id.lvdaichuli); //生成动态数组,加入数据 List<HashMap<String,Object>> listItem=new ArrayList<HashMap<String,Object>>(); int temp=0; int No=1; for(int i=0;i<(result.size()/3);i++) { HashMap<String,Object> map=new HashMap<String,Object>(); map.put("NO",No); map.put("ADSL",result.get(temp)); map.put("comName",result.get(temp+2)); listItem.add(map); temp+=3; No++; } //生成适配器的Item和动态数组对应的元素 SimpleAdapter listItemAdapter = new SimpleAdapter(Gddaichuli.this,listItem,R.layout.lvdaichuli,new String[] {"NO","ADSL","comName"},new int[] {R.id.txtNO,R.id.textView2,R.id.textView1}); //添加并且显示 list.setAdapter(listItemAdapter); mDialog.dismiss();//关闭数据加载动画 } } }; Runnable daichuli=new Runnable() { public void run() { getUrl u=new getUrl(); ArrayList result=new ArrayList(); result=u.daichuli(Uname); Message m=new Message(); if(!(result.equals(null))) { m.what=1; m.obj=result; } else { m.what=0; } h.sendMessage(m); } }; public void showRoundProcessDialog(int layout) { OnKeyListener keyListener = new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_HOME || keyCode == KeyEvent.KEYCODE_SEARCH) { return true; } return false; } }; mDialog = new AlertDialog.Builder(this).create(); mDialog.setCanceledOnTouchOutside(false); mDialog.setOnKeyListener(keyListener); mDialog.show(); // 注意此处要放在show之后 否则会报异常 mDialog.setContentView(layout); }} 第一段代码就可以了,我测试了,首先注意两个地方,tabHost.addTab(tabHost.newTabSpec(TAB_HOME) .setIndicator(TAB_HOME) .setContent(new Intent(this,Gddaichuli.class)));这里new Intent后面的this有点泛指,可能造成指针不对,我改成了activity名.this,然后tabHost.setCurrentTabByTag(TAB_HOME);改成了tabHost.setCurrentTag()里面的参数是int,0,1,2,自己选择第几个画面,运行没报错,,, 我试了一下还是不行,改成tabHost.addTab(tabHost.newTabSpec(TAB_HOME) .setIndicator(TAB_HOME) .setContent(new Intent(Gdhuidan.this,Gddaichuli.class))); 这样了还有这句tabHost.setCurrentTag(0);会报错:The method setCurrentTag(int) is undefined for the type TabHost 你的activity没有extends TabActivity吗?怎么会说这个方面没有了 有继承TabActivity 方便加你QQ聊吗? activity是继承TabTabActivity,所以你一直用tabhost报错了,,, 我试了一下把那句.setContent(new Intent(Gdhuidan.this,Gddaichuli.class))); 改成.setContent(new Intent(this,MainActivity.class)));在那选项卡中跳转到MainActivity.class这里是正常的,只是跳转到Gddaichuli.class这个页面才出错,但是在其他非选项卡页面直接跳转到Gddaichuli.class也是正常的 随手记中的自定义控件 js调用android方法,大家进来看看 应用植入万普世纪广告出错???????? Google Map:MapView的经纬度图标切换 sqlite计算时间差 40分求救!!下面的list怎么实现啊? 关于动画的一些问题,请大牛回答 家里电脑的eclipse和公司的eclipse里面的代码怎么实现呢 安卓辅助功能accesiibilityservice 怎么实现控件的长按操作 难,搞了1星期了,关于gradle的task无法执行的问题 android调用webservice时,传参无效,请高手指点 请教大家一个问题
try {
String uName=staticContent.uName;//获取用户名
//设置标题
TextView tvtitle=(TextView)findViewById(R.id.title);
tvtitle.setText("工单处理");
//设置显示用户名
TextView tvuname=(TextView)findViewById(R.id.txtUname);
tvuname.setText(uName);
group = (RadioGroup)findViewById(R.id.main_radio);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec(TAB_HOME)
.setIndicator(TAB_HOME)
.setContent(new Intent(this,Gddaichuli.class))); //.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)这句是选项卡切换刷新
tabHost.addTab(tabHost.newTabSpec(TAB_MES)
.setIndicator(TAB_MES)
.setContent(new Intent(this,MainActivity.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_TOUCH)
.setIndicator(TAB_TOUCH)
.setContent(new Intent(this,Gdhuidan.class)));
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_button0:
tabHost.setCurrentTabByTag(TAB_HOME);
break;
case R.id.radio_button1:
tabHost.setCurrentTabByTag(TAB_MES);
break;
case R.id.radio_button2:
tabHost.setCurrentTabByTag(TAB_TOUCH);
break;
default:
break;
}
}
});
} catch (Exception e) {
// TODO: handle exception
String error=e.toString();
Dialog alertDialog = new AlertDialog.Builder(this).
setTitle("1").
setMessage(error).
setIcon(R.drawable.nt2).
create();
alertDialog.show();
}
} Gddaichuli.java页面代码
try {
Uname=staticContent.LoginName;
//启动数据加载动画
showRoundProcessDialog(R.layout.loaddata);
newthread=new Thread(daichuli);
newthread.start();
} catch (Exception e) {
// TODO: handle exception
String error=e.toString();
Dialog alertDialog = new AlertDialog.Builder(this).
setTitle("对话框的标题").
setMessage(error).
setIcon(R.drawable.nt2).
create();
alertDialog.show();
}
}
final Handler h=new Handler(){
@Override
public void handleMessage(Message msg){
super.handleMessage(msg);
if(msg.what==0)
{
mDialog.dismiss();//关闭数据加载动画
Toast.makeText(getApplicationContext(),"没有数据",Toast.LENGTH_LONG).show();
}
if(msg.what==1)
{
ArrayList result=new ArrayList();
result=(ArrayList) msg.obj;
//绑定Layout里面的ListView
final ListView list = (ListView) findViewById(R.id.lvdaichuli);
//生成动态数组,加入数据
List<HashMap<String,Object>> listItem=new ArrayList<HashMap<String,Object>>();
int temp=0;
int No=1;
for(int i=0;i<(result.size()/3);i++)
{
HashMap<String,Object> map=new HashMap<String,Object>();
map.put("NO",No);
map.put("ADSL",result.get(temp));
map.put("comName",result.get(temp+2));
listItem.add(map);
temp+=3;
No++;
}
//生成适配器的Item和动态数组对应的元素
SimpleAdapter listItemAdapter = new SimpleAdapter(Gddaichuli.this,listItem,R.layout.lvdaichuli,new String[] {"NO","ADSL","comName"},new int[] {R.id.txtNO,R.id.textView2,R.id.textView1});
//添加并且显示
list.setAdapter(listItemAdapter);
mDialog.dismiss();//关闭数据加载动画
}
}
};
Runnable daichuli=new Runnable() {
public void run() {
getUrl u=new getUrl();
ArrayList result=new ArrayList();
result=u.daichuli(Uname);
Message m=new Message();
if(!(result.equals(null)))
{
m.what=1;
m.obj=result;
}
else {
m.what=0;
}
h.sendMessage(m);
}
}; public void showRoundProcessDialog(int layout)
{
OnKeyListener keyListener = new OnKeyListener()
{ @Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_HOME || keyCode == KeyEvent.KEYCODE_SEARCH)
{
return true;
}
return false;
}
}; mDialog = new AlertDialog.Builder(this).create();
mDialog.setCanceledOnTouchOutside(false);
mDialog.setOnKeyListener(keyListener);
mDialog.show();
// 注意此处要放在show之后 否则会报异常
mDialog.setContentView(layout);
}
}
.setIndicator(TAB_HOME)
.setContent(new Intent(this,Gddaichuli.class)));这里new Intent后面的this有点泛指,可能造成指针不对,我改成了activity名.this,然后tabHost.setCurrentTabByTag(TAB_HOME);改成了tabHost.setCurrentTag()里面的参数是int,0,1,2,自己选择第几个画面,运行没报错,,,
tabHost.addTab(tabHost.newTabSpec(TAB_HOME)
.setIndicator(TAB_HOME)
.setContent(new Intent(Gdhuidan.this,Gddaichuli.class))); 这样了
还有这句tabHost.setCurrentTag(0);会报错:The method setCurrentTag(int) is undefined for the type TabHost