【发布时间】:2011-11-25 15:48:59
【问题描述】:
我有三个 2 选项卡 TabA 和 TabB。 TabA 显示值它没问题。现在在 Tab2 我有显示值的列表视图。每当我单击 listitem 值时,该值必须传递给下一个活动,并且每次单击 listItem 时都必须根据该值创建新选项卡,应该生成选项卡。我的问题是在 listitem intent = new Intent() 的点击事件中不受支持。我的代码如下
public class FriendLists extends TabActivity {
//Declarations
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.friendtab);
connection=XMPPLogic.getInstance().getConnection();
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
lv=(ListView) findViewById(R.id.footerlist);
adapter = new ArrayAdapter<String>(this,R.layout.listitems,R.id.list_content, my_own_listarray);
lv.setAdapter(adapter);
//end of listing friends
final AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick( AdapterView<?> parent, View v, int position, long id){
//problem is here when i try to put intent and pass String S it creates a problem
String S=group.get(position).toString();
// spec = tabHost.newTabSpec(S).setIndicator(S,
// res.getDrawable(R.drawable.tab_friendlist))
// .setContent(null);
// tabHost.addTab(spec);
// set the message to display
alertbox.setMessage(S).show();
}});
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this,Friends.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("friendlist").setIndicator("Friend List",
res.getDrawable(R.drawable.tab_friendlist))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
tabHost.addTab(tabHost.newTabSpec("onlinefriends").setIndicator("Online Friends",
res.getDrawable(R.drawable.tab_friendlist))
.setContent(R.id.footerlist));
}
}
【问题讨论】:
-
“不支持”是什么意思?它不编译还是产生异常?
-
构造函数 Intent(new AdapterView.OnItemClickListener(){}, Class
) 未定义...这是我声明 intent=new Intent(this,destination.class) 时显示的消息..
标签: android listview tabs android-intent