I have three 2 tab TabA and TabB. TabA displays value its ok. Now in Tab2 i have listview displaying the values. Whenever I click the listitem value that value have to pass to the next activity and new tab have to be created based on that value every time I click the listItem the tab should be generated. My problem is inside the click event of listitem intent = new Intent() is not supported. My code is as follows
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));
}
}
From inside an anonymous inner class, you cannot refer to a non-final local variable (
intent) that was declared outside of it.I assume you just need a temporary variable to hold the intent you want to pass to
setContent. Just declare it insideonItemClick: