我有三個2選項卡TabA和TabB。 TabA顯示值正確。現在在Tab2我有ListView顯示值。每當我單擊listitem值時,必須將值傳遞給下一個活動,並且每次單擊listItem時都必須基於該值創建新選項卡,則應該生成該選項卡。我的問題是在listitem intent = new Intent()的click事件中不受支持。我的代碼如下選項卡,列表視圖和意圖
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));
}
}
你是什麼意思的「不支持」?它不編譯或它會產生異常? – Hicham
構造函數Intent(new AdapterView.OnItemClickListener(){},類)未定義...這是當我聲明intent = new Intent(this,destination.class)時顯示的消息.. –
Shalawei