Android 选项卡上的ListView不起作用

Android 选项卡上的ListView不起作用,android,listview,tabs,Android,Listview,Tabs,我是新的android程序员,想做一些有列表视图的选项卡。应用程序可以工作,但必须显示listview的选项卡不能工作。代码如下: main_menu.xml是我的tabhost,MainActivity.java是我的主要活动: 下一个类生成必须显示在第二个选项卡中的arrayList 最后是适配器: tabhost运行良好,但listView 希望您能帮助我,非常感谢。好的,我发现了问题。Pestana_事件和Pestana_朋友不是活动。这些列表没有显示出来,因为它们没有项目。未调用必须设

我是新的android程序员,想做一些有列表视图的选项卡。应用程序可以工作,但必须显示listview的选项卡不能工作。代码如下:

main_menu.xml是我的tabhost,MainActivity.java是我的主要活动:

下一个类生成必须显示在第二个选项卡中的arrayList

最后是适配器:

tabhost运行良好,但listView


希望您能帮助我,非常感谢。

好的,我发现了问题。Pestana_事件和Pestana_朋友不是活动。这些列表没有显示出来,因为它们没有项目。未调用必须设置项目的代码。

y您不能使用片段吗?框架布局中的2个线性布局具有高度匹配父值。是的,因为每个布局都是一个选项卡。这不正确吗?请问,为什么ListView没有显示在选项卡中?是的,这就是问题所在。谢谢你!
<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"
tools:context=".Pestana_eventos" >

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

    <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" />

        <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="vertical" >
                <TextView
                    android:id="@+id/bienvenida2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Pestaña de perfil ." />
            </LinearLayout>
            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <ListView
                    android:id="@+id/listaEventos"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    tools:listitem="@layout/eventolist" >
                </ListView>
            </LinearLayout>

        </FrameLayout>
    </LinearLayout>
</TabHost>
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);

    Resources res= getResources();
    TabHost contenedor= (TabHost)findViewById(android.R.id.tabhost);
    contenedor.setup();

    //Intent intent= new Intent().setClass(this, Pestana_perfil.class); // Cogemos la información de la clase asociada con la pestaña
    TabHost.TabSpec spec= contenedor.newTabSpec("pestana_perfil");
    spec.setContent(R.id.tab1);
    spec.setIndicator("",res.getDrawable(R.drawable.ic_tab_perfil));
    contenedor.addTab(spec);

    contenedor.setup();
    //intent= new Intent().setClass(this, Pestana_eventos.class); 
    TabHost.TabSpec spec2 =  contenedor.newTabSpec("pestana_eventos");
    spec2.setContent(R.id.tab2);
    spec2.setIndicator("",res.getDrawable(R.drawable.ic_tab_eventos));
    contenedor.addTab(spec2);


    contenedor.setCurrentTab(0);
}
public class Pestana_eventos extends Activity {
public void onCreate(Bundle savedInstanceState){ //Enlazamos los .java con los xml
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);

    ListView lista= (ListView) findViewById(R.id.listaEventos);
    ArrayList<Evento> arrayEventos= new ArrayList<Evento>();
    Evento evento;

    //Introduccion de datos en el array. Aqui es donde se deben cargar los datos de la BB.DD
    evento= new Evento(getResources().getDrawable(R.drawable.conferencia),"Nuevos metodos de programacion","Aula Magna","20/12/2014-18:00");
    arrayEventos.add(evento);
    evento= new Evento(getResources().getDrawable(R.drawable.playita),"Dia en la playa","Muskiz","20/8/2015-10:00");
    arrayEventos.add(evento);
    evento= new Evento(getResources().getDrawable(R.drawable.fevernight),"Sabado Noche","Fever","29/11/2014-22:00");
    arrayEventos.add(evento);
    // Creamos el adapter
    EventoAdapter adapter= new EventoAdapter(this,arrayEventos);
    // Una vez hecha la conexión pasamos los datos.
    lista.setAdapter(adapter);
}
@SuppressLint("InflateParams") 
public class EventoAdapter extends BaseAdapter {

protected Activity activity;
protected ArrayList<Evento> eventos;

public EventoAdapter(Activity activity, ArrayList<Evento> eventos){
    this.activity= activity;
    this.eventos= eventos;
}

@Override
public int getCount() {
    return eventos.size();
}

@Override
public Object getItem(int position) {
    return eventos.get(position);
}

@Override
public long getItemId(int position) {
    return eventos.get(position).getId();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    //Mejorar eficiencia con el convertView
    View v= convertView;
    //Asociar el layout de la lista que hemos creado.
    if(convertView == null){
        LayoutInflater inf= (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v=inf.inflate(R.layout.eventolist,null);
    }
    //Definimos un objeto a partir del array, vamos a cargar el contenido
    //de ese objeto en el view de la lista.
    Evento evento= eventos.get(position);
    //Cargamos la fotografía del evento.
    ImageView foto= (ImageView)v.findViewById(R.id.fotoEvento);
    foto.setImageDrawable(evento.getFoto());
    //Cargamos el nombre del evento
    TextView nombre= (TextView)v.findViewById(R.id.nombreEvento);
    nombre.setText(evento.nombreEvento);
    //Cargamos el lugar del evento.
    TextView lugar= (TextView)v.findViewById(R.id.lugarEvento);
    lugar.setText(evento.lugar);
    //Cargamos la fecha del evento
    TextView fecha= (TextView)v.findViewById(R.id.fechaEvento);
    fecha.setText(evento.fecha);
    //Se devuelve la view cargada
    return v;

}