如果选项卡和活动不在一起......有没有办法作弊?
我很难将我的活动放入选项卡中。我有一个活动可以解析 XML 文件并将它们放入列表中,并且它本身可以完美运行。当我在选项卡上调用它时,它不起作用(我收到可怕的“抱歉!等等……意外停止”提示...顺便说一句,是的,我做了清单)。
我已将这些活动迁移为一项活动,瞧!成功了!!!然而,这不是我们想要的这个项目的方式——我们真的需要有单独的活动。
许多人发现选项卡和活动不能很好地协同工作,有没有办法解决这个问题?也许某种乳化剂?
这是代码:
导入android.app.Activity; 导入 android.content.Intent; 导入 android.os.Bundle; 导入 android.widget.TabHost; 导入 android.widget.Toast;
public class TabDemo extends Activity{
/** data members go here*/
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
try {
TabHost tabs= (TabHost)findViewById(R.id.tabhost);
tabs.setup();
Intent callResultHits = new Intent(this, my.tabebd.layout.ResultHits.class);
TabHost.TabSpec spec = tabs.newTabSpec("tag1");
spec.setContent(callResultHits);
spec.setIndicator("Result", getResources().getDrawable(R.drawable.ic_tab_search_result) );
tabs.addTab(spec);
spec = tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("Details",getResources().
getDrawable(R.drawable.ic_tab_details));
tabs.addTab(spec);
tabs.setCurrentTabByTag("tag1");
} catch (Throwable t) {
// TODO Auto-generated catch block
Toast.makeText(this, "Exception: " + t.toString(), 50000).show();
}
}
这里是活动之一...
public class ResultHits extends Activity implements OnItemClickListener {
ListView listView_titles;
ArrayList<String> items = new ArrayList<String>();
String [] test = {"1", "2","3"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView_titles = (ListView)findViewById(R.id.list);
listView_titles.setAdapter(new ArrayAdapter<String>
(this,R.layout.row, R.id.row_text,test));
}
}
我省略了 xml 解析部分...如果这个基本列表可以显示在选项卡中那么它就完美了。提前TY
BTW setcurrenttabByTag 之前是setCurrenttab(2)..实际上我做了这些值0,1,2,3以防万一;)
I am having a real hard time on putting my activities in tabs. I have an activity that parses an XML file and puts them on a list, and it works perfectly on its own. When I call it on a tab however it does not work (i get the dreaded "Sorry! blah blah.. has stopped unexpectedly" prompt... BTW yes I did the manifest).
I have migrated the activities to work as one activity, voila! it worked!!! However this is not the way we wanted to go with this project - WE REALLY NEED to have separate activities.
So as many people had found out that tabs and activities doesn't work well together is there a way to work around it? Some sort of emulsifier maybe?
Here is the code:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.Toast;
public class TabDemo extends Activity{
/** data members go here*/
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
try {
TabHost tabs= (TabHost)findViewById(R.id.tabhost);
tabs.setup();
Intent callResultHits = new Intent(this, my.tabebd.layout.ResultHits.class);
TabHost.TabSpec spec = tabs.newTabSpec("tag1");
spec.setContent(callResultHits);
spec.setIndicator("Result", getResources().getDrawable(R.drawable.ic_tab_search_result) );
tabs.addTab(spec);
spec = tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("Details",getResources().
getDrawable(R.drawable.ic_tab_details));
tabs.addTab(spec);
tabs.setCurrentTabByTag("tag1");
} catch (Throwable t) {
// TODO Auto-generated catch block
Toast.makeText(this, "Exception: " + t.toString(), 50000).show();
}
}
here is one of the activities...
public class ResultHits extends Activity implements OnItemClickListener {
ListView listView_titles;
ArrayList<String> items = new ArrayList<String>();
String [] test = {"1", "2","3"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView_titles = (ListView)findViewById(R.id.list);
listView_titles.setAdapter(new ArrayAdapter<String>
(this,R.layout.row, R.id.row_text,test));
}
}
I omitted the xml parsing part... if this basic list can be shown inside the tab then it will be perfect. TY in advance
BTW setcurrenttabByTag was previously setCurrenttab(2)..actualy i did these values 0,1, 2, 3 just in case ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发布您的代码我认为您将活动放入每个选项卡中不会有问题,
这是如何将活动放入选项卡的基本示例,
Post your code I think you will not have problems putting activities into every tab,
This is a basic Example of how put activities in tabs,