2013-05-06 1 views
0

Я пытаюсь поставить ListView под другим ListView на первой вкладке, используя tabhost.Как отобразить ListView с заголовком под другим ListView все в Tab1 TabHost?

Причина, по которой я хочу, так это потому, что я хочу разделить список торговых карт по типу, поэтому я думаю, что создаю разделы или что-то еще.

Вот мой .xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/banlistdate" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#000000" 
     android:text="Banlist Date: March, 2013" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#FFFFFF" /> 

    <TabHost 
     android:id="@+id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/banlistdate" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
      </TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <LinearLayout 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="horizontal" > 

        <ListView 
         android:id="@+id/fLV1" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:background="#FF8B53" 
         tools:listheader="@layout/banlist_header_effectmonsters" > 
        </ListView> 

        <ListView 
         android:id="@+id/fLV2" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:background="#a086b7" 
         tools:listheader="@layout/banlist_header_fusionmonsters" > 
        </ListView> 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

        <ListView 
         android:id="@+id/flv3" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" > 
        </ListView> 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

        <ListView 
         android:id="@+id/listView1" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" > 
        </ListView> 
       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

</LinearLayout> 

Вот мой основной Java-файл, чтобы начать вкладки и настройки ListViews:

package cybertech.productions.yugiohlibrary; 

import java.util.ArrayList; 
import java.util.Arrays; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 
import android.widget.TextView; 

public class Banlist extends Activity implements OnClickListener { 

    TabHost th; 

    Initializers initialMngr; 

    ArrayAdapter<String> listAdapter; 
    ListView forbiddenEMListView, forbiddenFListView; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.banlist); 
     th = (TabHost) findViewById(R.id.tabhost); 
     th.setup(); 
     TabSpec specs = th.newTabSpec("tag1"); 
     specs.setContent(R.id.tab1); 
     specs.setIndicator("Forbidden"); 
     th.addTab(specs); 
     specs = th.newTabSpec("tag2"); 
     specs.setContent(R.id.tab2); 
     specs.setIndicator("Semi-Limited"); 
     th.addTab(specs); 
     specs = th.newTabSpec("tag3"); 
     specs.setContent(R.id.tab3); 
     specs.setIndicator("Limited"); 
     th.addTab(specs); 

     th.setCurrentTab(0); 

     // #BEGIN: Tab 1 ListViews 
     //Setup the "forbidden" ListView(s); 

     // ListView 1: Effect Monsters 
     forbiddenEMListView = (ListView) findViewById(R.id.fLV1); 
     ArrayList<String> forbiddenEMList = new ArrayList<String>(); 
     forbiddenEMList.addAll(Arrays.asList(initialMngr.forbiddenEM)); 
     listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenEMList); 
     View effectMon_header = View.inflate(this, R.layout.banlist_header_effectmonsters, null); 
     forbiddenEMListView.addHeaderView(effectMon_header); 
     forbiddenEMListView.setAdapter(listAdapter); 

     // ListView 2: Fusion Monsters 
     forbiddenFListView = (ListView) findViewById(R.id.fLV2); 
     ArrayList<String> forbiddenFList = new ArrayList<String>(); 
     forbiddenFList.addAll(Arrays.asList(initialMngr.forbiddenF)); 
     listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenFList); 
     View fusion_header = View.inflate(this, R.layout.banlist_header_fusionmonsters, null); 
     forbiddenFListView.addHeaderView(fusion_header); 
     forbiddenFListView.setAdapter(listAdapter); 
     // #END: Tab 1 ListViews 
    } 

    @Override 
    public void onClick(View arg0) { 
     // TODO Auto-generated method stub 

    } 

} 

Спасибо за любую помощь.

ответ

0

Вы хотите использовать ExpandableListView. Используйте представления групп для обозначения различных категорий или разделов. Поскольку вы используете массивы для поддержки своих списков, SimpleExpandableListAdapter должен хорошо соответствовать счету.

+0

Благодарим вас, я попробую его позже и сообщит вам, как это работает. –

Смежные вопросы