Warum ist Android TabHost stehlen Fokus von einem TextView?
Ich habe eine Anwendung mit dem folgenden layout :
alt-text http://img15.imageshack.us/img15/238/screenshot003xbo.png
Wenn Sie die app starten, wird der Fokus auf die erste TextView, aber wenn Sie versuchen, geben Sie den Buchstaben, der Fokus geht direkt zu den tabs. Es scheint, dass ich nicht der einzige bin,kämpfen mit diesem Problem, und vielleicht ist dies im Zusammenhang mit den folgenden :
Trotzdem haben Sie keine Idee warum das passiert ? Und natürlich, Abhilfe würde geschätzt.
Poste ich den code unten, um eine überlastung der Frage :
XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:padding="5px"
android:orientation="vertical"
android:id="@+id/task_edit_panel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50" >
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"
android:textStyle="bold" />
<EditText android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<TabHost android:id="@+id/edit_item_tab_host"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="65px"> <!-- you need that if you don't want the tab content to overflow -->
<LinearLayout
android:id="@+id/edit_item_date_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/edit_item_geocontext_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lieu"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/edit_item_text_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px">
<EditText android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" />
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>
<!-- Bottom pannel with "add item" button -->
<LinearLayout
android:padding="5px"
android:orientation="horizontal"
android:layout_weight="1"
android:id="@+id/task_edit_panel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#E7E7E7" >
<!-- Let the height set to fill_parent until we find a better way for the layout -->
<Button android:id="@+id/item_edit_ok_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/ok"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1" />
<Button android:id="@+id/item_edit_cancel_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/cancel"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Dem Java code :
TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
//don't forget this setup before adding tabs from a tabhost using a xml view or you'll get an nullpointer exception
tab_host.setup();
TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
ts1.setIndicator(getString(R.string.when), getResources().getDrawable(R.drawable.ic_dialog_time));
ts1.setContent(R.id.edit_item_date_tab);
tab_host.addTab(ts1);
TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
ts2.setIndicator(getString(R.string.where), getResources().getDrawable(R.drawable.ic_dialog_map));
ts2.setContent(R.id.edit_item_geocontext_tab);
tab_host.addTab(ts2);
TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
ts3.setIndicator(getString(R.string.what), getResources().getDrawable(R.drawable.ic_menu_edit));
ts3.setContent(R.id.edit_item_text_tab);
tab_host.addTab(ts3);
tab_host.setCurrentTab(0);
InformationsquelleAutor e-satis | 2009-04-24
Du musst angemeldet sein, um einen Kommentar abzugeben.
Naja, auf jeden Fall ein bug : http://code.google.com/p/android/issues/detail?id=2516.
Hoffe das es behoben wird in der nächsten Version, weil das ist eine wirklich nervige Probleme für komplexe apps mit einem erweiterten layout.
InformationsquelleAutor e-satis
Ich Stand vor der gleichen Art von Problem mit HoneyComb, sondern fand eine ganz einfache Lösung. So dachte ich, kann es hilfreich sein für jemanden, der um meine Erfahrung zu teilen. Jedes mal, wenn eine Registerkarte geklickt wird, wird der Fokus auf Text Bearbeiten, und Sie können tatsächlich geben Sie mit harten Tastatur, aber die virtuelle Tastatur nie erscheint. Auch mit dem code unten, ist es nicht das Problem zu lösen:
Lösung:
In der main-Klasse, wo Sie mit Tabs, schreiben Sie einfach unten in Java-code:
InformationsquelleAutor Haider
Wenn es nicht in Beziehung zum anderen Fehler hingewiesen (und es sieht aus wie es wahrscheinlich ist) und wenn Sie erleben diese auf der G1s (und nicht der emulator) ich vermute dein problem ist, dass der Fokus entweder nicht eingefroren ist, bevor Sie die Ausrichtung ändern (wenn Sie Falten Sie die Tastatur und gehen Sie in landscape-Modus) oder aufgetaut, nachdem die Ansicht neu erstellt wird. Sie könnten versuchen, das Überschreiben der Aktivität onSaveInstanceState() und onRestoreInstanceState() Methoden zum speichern/wiederherstellen der Fokus.
InformationsquelleAutor
in diesem Beispiel zeigen, wie dieses Problem zu beheben:
InformationsquelleAutor Oleksandr Bodashko
nach dem hinzufügen alle Angaben hinzufügen requestFocus Methode, um Ihre edittext in java-Datei
EditText
überschreiben Sie dierequestFocus
Methode und verwenden Sie es anstelle des standard -EditText
beim erstellen der UI?InformationsquelleAutor Hardik Bamania