I have TabHost with ListView as tab content. ListView has context menu
that opens send SMS activity.
After returning from SMS screen when I try to switch tab ListView
disappears and can not be displayed for second tab until application
is restarted.
I made simple example if someone can confirm this issue, please follow
steps at the bottom:
public class TabHostListView extends TabActivity implements
TabHost.TabContentFactory {
/** Called when the activity is first created. */
private String mListOfResults[] = {"item1", "item2", "item3"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost.TabSpec spec=getTabHost().newTabSpec("First");
spec.setContent(this);
spec.setIndicator("First");
getTabHost().addTab(spec);
spec=getTabHost().newTabSpec("Second");
spec.setContent(this);
spec.setIndicator("Second");
getTabHost().addTab(spec);
}
@Override
public View createTabContent(String arg0) {
// create list here
LayoutInflater inflater = LayoutInflater.from(getBaseContext
());
ListView mLV = (ListView)inflater.inflate
(R.layout.list_layout, null);
mLV.setAdapter(new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,mListOfResults));
registerForContextMenu(mLV);
return mLV;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// Display sms action
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Actions menu");
menu.add(0, 0, 0, "SMS");
}
public boolean onContextItemSelected(MenuItem item) {
/* Send SMS */
try {
String phone = "123123";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts
("sms", phone, null)));
} catch (ActivityNotFoundException e) {
Toast.makeText(getBaseContext(), R.string.failed,
Toast.LENGTH_SHORT).show();
Log.e("EdithActivity", "SMS Contact failed" );
}
return super.onContextItemSelected(item);
}
}
list_layout xml file:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listTabView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
Steps to reproduce the bug:
Start program -> there are two tabs and a list.
Select list item with longpress -> Context menu appears.
Click SMS -> SMS app appears.
Type in few letters and press back -> Toast is displayed, and your are
back to test activity.
Try to switch to tab 2 -> there is no content in tab2! List is not
displayed!
Make sure you dont go to tab2 first, then it works ok!
Make sure you type few letters (at least one) in SMS window, if you
return immediately - it works ok too.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---