Я пытаюсь поместить MapActivity и ListActivity во вкладки. Я нашел способ сделать это, но мне просто не нравится, как это выглядит (я скорее использую некоторые классы, чтобы сделать мой код более модульным)
Теперь у меня есть этот код в моей основной деятельности:
Resources res = getResources(); // Resource object to get Drawables
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, OptionsActivity.class);
spec = tabHost.newTabSpec(OPTS_TAB_TAG).setIndicator("Options",
res.getDrawable(R.drawable.ic_tab_options))
.setContent(intent);
tabHost.addTab(spec);
А это в классе OptionsActivity:
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class OptionsActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] options = getResources().getStringArray(R.array.options_array);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, options));
ListView lv = getListView();
lv = (ListView) findViewById(R.id.opt);
lv.setEmptyView((TextView) findViewById(R.id.options));
lv.setTextFilterEnabled(true);
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, options));
}
}
и мой макет main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<TextView
android:id="@+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
<ListView
android:id="@+id/opt"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<TextView
android:id="@+id/options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0fFbO-eNMhj2lDaC6b4YBfpo1DikBMixPYiEJCw" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Но по какой-то причине, когда я выбираю эту вкладку "Параметры", мое приложение закрывается принудительно ...
Может кто-нибудь показать мне, что я здесь не так делаю?