Listview en el lado de rleft y tabhost en el lado derecho con la proporción de 20:80 compartir pantalla

Hola, he agregado dos TabHost s en la Activity y su funcionamiento muy bien. He añadido otro archivo XML con ListView y se llama en la Activity donde estoy usando el Tabhost . Es dar error como se esperaba, pero he intentado mucho, pero no pudo resolverlo. ¿Podría alguien darme alguna idea acerca de cómo administrar ListView y TabHost tanto en una Activity ? No puse el código ya que es sobre todo de tutoriales. Cualquier ayuda sería apreciada. Gracias. El error principal es "su contenido debe tener un TabHost cuyo atributo id es 'android.R.id.tabhost'"

Ejemplo de actividad con pestañas y ListViews con elementos marcados:

TabHost debajo de una actividad de ejemplo que contiene un TabHost que tiene 3 Tabs y dos ListView , uno en cada tab1 y tab3 . Utilizo un ArrayList para inicializar mi ArrayAdapter del cual puedo ligar mi ListView . A continuación, agregar elementos a la tab3ListView después de que se configura a través de su ArrayList , tab3List . Tenga en cuenta que los elementos de tab3ListView tienen una casilla de verificación correspondiente. Tenga en cuenta que hoy en día algunas personas prefieren ActionBar.Tabs que TabHost pero me parece que esta manera más simple.

XML FILE:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabHost android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="5dp" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="70dp" android:layout_marginBottom="-4dp" android:layout_weight="0" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="0dp" android:layout_weight="1"> <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ListView android:id="@+id/tab1List" android:layout_width="match_parent" android:layout_height="wrap_content" android:fastScrollEnabled="true"></ListView> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/tab2Edit1" android:layout_width="fill_parent" android:layout_height="40dp" android:hint="Enter text here"/> </LinearLayout> <LinearLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ListView android:id="@+id/tab3List" android:layout_width="match_parent" android:layout_height="wrap_content" android:fastScrollEnabled="true"></ListView> </LinearLayout> </FrameLayout> </LinearLayout> </TabHost> </LinearLayout> 

Actividad principal:

 public class MainActivity extends Activity{ // TabHost TabHost th; LinearLayout tab1, tab2, tab3; // ListView ListView tab1ListView, tab3ListView; // String list String stringList[] = {"Paris", "Washington", "Amsterdam", "London", "Bale", "Madrid", "Zurich", "Munich", "Berlin", "Milan", "Rome", "Turin", "Lyon", "Marseille"}; // Adapters ArrayList<String> tab1List, tab3List; ArrayAdapter<String> tab1Adapter, tab3Adapter; // Others EditText tab2Edit1; @Override protected void onCreate(Bundle savedInstanceState) { // Initialize Layout super.onCreate(savedInstanceState); setContentView(R.layout.main); // Initialize Tabs th = (TabHost) findViewById(R.id.tabhost); th.setup(); // Tab1 TabSpec spec1 = th.newTabSpec("tag1"); spec1.setContent(R.id.tab1); spec1.setIndicator("Tab 1"); th.addTab(spec1); // Tab2 TabSpec spec2 = th.newTabSpec("tag2"); spec2.setContent(R.id.tab2); spec2.setIndicator("Tab 2"); th.addTab(spec2); // Tab3 TabSpec spec3 = th.newTabSpec("tag3"); spec3.setContent(R.id.tab3); spec3.setIndicator("Tab 3"); th.addTab(spec3); //Initialize Adapter and ListView from Tab1 tab1ListView = (ListView) findViewById(R.id.tab1List); tab2Edit1 = (EditText) findViewById(R.id.tab2Edit1); tab1List = new ArrayList<String>(Arrays.asList(stringList)); tab1Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tab1List); tab1ListView.setAdapter(tab1Adapter); //Initialize Adapter and ListView from Tab3 tab3ListView = (ListView) findViewById(R.id.tab3List); tab3List = new ArrayList<String>(Arrays.asList(stringList)); tab3Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, tab3List); tab3ListView.setAdapter(tab3Adapter); tab3ListView.setFocusable(false); tab3ListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Modify ListView: modify ArrayList and call notifyDataSetChanged() from corresponding adapter tab3List.add(0,"New item at location 0"); tab3List.add(3,"New item at location 3"); tab3List.add("New item at location end"); tab3Adapter.notifyDataSetChanged(); tab3ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Set what happenss when you check or uncheck an item here } }); } 
  • Cómo acoplar el diseño relativo al fondo de la pantalla
  • Dibujar lienzo en el widget de pantalla de inicio
  • Efecto extraño con ImageView startAnimation en ListView
  • Uso del selector para cambiar el color de texto de TextView
  • Android: cómo borrar un edittext mediante botón cruzado en el lado derecho
  • Reproducir video de youtube en WebView
  • ¿Cómo actualizar vista de un widget en el botón de clic en android?
  • App Widget no aparece en la lista de widgets en dispositivos Honeycomb hasta que se reinicie la aplicación
  • Establecer el ancho de diseño infantil de forma programática En ANDROID?
  • No se puede cambiar el tamaño del texto del pulgar del widget SwitchCompat
  • ¿Cómo actualizar SeekBar no disparar OnSeekBarChangeListener?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.