当前位置:编程学习 > wap >>

求助!关于TabHost中向另外一个Activity传数据问题

写了一个TabActivity,想要在每个tab里面都用个ListView从数据库添加所要的数据。通过TabHost的实例化对象tabhost.setcontent(intent)方法连接ListView的Activity,但想通过intent传递个数据过去,用来辨别要显示哪些数据。
用了tabhost.setContent(intent.putExtras(cn.edu.nuc.lookTab.this.notSentBundle),但报错了。(notSentBundle是我创建的用来传数据的Bundle类对象)
求指点!! --------------------编程问答-------------------- 是什么异常,是不是setup(LocalActivityManager activityGroup),要你去建activityGroup? --------------------编程问答--------------------
引用 1 楼  的回复:
是什么异常,是不是setup(LocalActivityManager activityGroup),要你去建activityGroup?
不是,不过现在已经解决啦~不过还有点小问题。
我创建了三个Bundle的对象,要分别在三个Tab里面使用。但传到另一个Activity里面后,头一个notSentBundle传过去的数据是正确的,就是notSent。但后两个传过去的数据都是第三个draftboxBundle的数据draftbox。请问这是怎么回事啊?
notSentBundle = new Bundle();
notSentBundle.putString("text", "notSent");
sentBundle = new Bundle();
sentBundle.putString("text", "sent");
draftboxBundle = new Bundle();
draftboxBundle.putString("text", "draftbox");

lookTabHost.addTab(lookTabHost.newTabSpec("One")
.setIndicator("", getResources().getDrawable(R.drawable.contact_photo))
.setContent(R.id.firstTabID)
.setContent(intent)
.setContent(intent.putExtras(cn.edu.nuc.lookTab.this.notSentBundle))
);

lookTabHost.addTab(lookTabHost.newTabSpec("Two")
.setIndicator("", getResources().getDrawable(R.drawable.contact_photo))
.setContent(R.id.secondTabID)
.setContent(intent)
.setContent(intent.putExtras(cn.edu.nuc.lookTab.this.sentBundle))
);

lookTabHost.addTab(lookTabHost.newTabSpec("Three")
.setIndicator("", getResources().getDrawable(R.drawable.contact_photo))
.setContent(R.id.thirdTabID)
.setContent(intent)
.setContent(intent.putExtras(cn.edu.nuc.lookTab.this.draftboxBundle))
); --------------------编程问答-------------------- 你怎么每一段都有一个.setContent(intent)?
我的一些例子:
 TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost);
        tabhost.setup(this.getLocalActivityManager());
        Intent intent1 = new Intent(this,Second.class);
        Bundle bundle1 = new Bundle();
        bundle1.putStringArray("string", strings1);
        bundle1.putFloatArray("values", values1);
        intent1.putExtra("bundle",bundle1);
        
        Intent intent2 = new Intent(this,Second.class);
        Bundle bundle2 = new Bundle();
        bundle2.putStringArray("string", strings2);
        bundle2.putFloatArray("values", values2);
        intent2.putExtra("bundle",bundle2);
        
        Intent intent3 = new Intent(this,Second.class);
        Bundle bundle3 = new Bundle();
        bundle3.putStringArray("string", strings3);
        bundle3.putFloatArray("values", values3);
        intent3.putExtra("bundle",bundle3);
        
        tabhost.addTab(tabhost.newTabSpec("tab1").setIndicator("spec1").setContent(intent1));
        tabhost.addTab(tabhost.newTabSpec("tab2").setIndicator("spec2").setContent(intent2));
        tabhost.addTab(tabhost.newTabSpec("tab3").setIndicator("spec3").setContent(intent3));
--------------------编程问答--------------------
引用 3 楼  的回复:
你怎么每一段都有一个.setContent(intent)?
我的一些例子:
Java code
 TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost);
        tabhost.setup(this.getLocalActivityManager());
        Intent intent1 = ne……
哦哦~我本来想的三个tab都要用同一个Activity,所以就用了一个intent……现在换成用三个就没问题啦!!谢谢指点!
另外还有个问题问一问哈、、我ListView的Activity里面,List是用的自己写的BaseAdapter的子类。里面写了三个Text和一个ToggleButton(请原谅我这个新手不会往这里面加图片……)。但现在只有ToggleButton有焦点,List没焦点。网上看资料说在布局文件里把ToggleButton设置为没焦点的就可以了。可是怎么设置了?或者还有其他办法?
补充:移动开发 ,  Android
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,