In the first tab I have a listview from where I extract a string, and in the second tab I have a textview. When i click an item in the list, I should go in the second tab and and the string value should be displayed in the textview.
public static String mystring;
protected void onListItemClick (ListView l, View v, int position, long id){
super.onListItemClick(l, v, position, id);
mystring = listofHashMap.get(position).get("keyname").toString(); //it's ok here
Intent intent=new Intent(this, MyActivity.class);
startActivity(intent);
}
The code above(placed in ListViewActivity) is what i have tried and it works (but MyActivity is not anymore a tabcontent,it is a full-screen standalone activity), having the following code snippet in MyActivity:
tv = (TextView)findViewById(R.id.tvid);
lv = new ListViewActivity();
tv.setText(lv.mystring);
But, as I said I want that MyActivity to be a tabcontent,so I have tried this:
public MyTabActivity taba = new MyTabActivity();
protected void onListItemClick (ListView l, View v, int position, long id){
super.onListItemClick(l, v, position, id);
mystring = listofHashMap.get(position).get("keyname").toString();
int i=1;//the tab where I want to go, and MyActivity is its content
taba.ChangeTab(i);
}
ChangeTab() is a static method within MyTabActivity(the activity that extends TabActivity ) which simply does setCurrentTab(i) .
So, doing this, MyActivity will always display the name of first clicked item, even I select other items in the list then.I belive that what i have to do is setContent() again for MyActivity or do something with that static String mystring, I have tried many solutions but with no result. I tried to be as accurate I could on what i want to do, please some help on this issue.
My suggestion would be to use a broadcast. I think that the timing would require a sticky broadcast. Maybe something like this:
And then in MyActivity, write something like this:
For the sticky broadcast, there’s an additional permission needed in the manifest. I’m not sure but maybe you could just send a regular broadcast if you swapped the order of sending the broadcast and changing the tab.