如何显示列表视图中的所有项目

时间:2016-10-11 10:54:09

标签: java android xml-layout

我试图在我的应用程序中已存在的屏幕上包含ListView。 我的问题是ListView只显示第一个项目。我希望是的 显示所有列表。

这是我的屏幕xml:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/radialback"
    android:orientation="vertical">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:isScrollContainer="true"
        android:orientation="vertical"
        android:shrinkColumns="*">

        <TableLayout
            android:id="@id/tabela_cuerpo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:stretchColumns="0">

            <TableRow
                android:id="@id/tableRow0"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TextView
                    android:id="@id/textView1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/tabela_cabecalho"
                    android:gravity="center_horizontal"
                    android:text="Corrida Recebida"
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"
                    android:textStyle="bold"/>
            </TableRow>

            <TableRow
                android:id="@id/tableRow1"
                android:layout_height="fill_parent">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text="Cliente: "
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"
                    android:textStyle="bold"/>

                <TextView
                    android:id="@id/txtPassageiro"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text=""
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"/>
            </TableRow>

            <TableRow
                android:id="@id/tableRow2"
                android:layout_height="fill_parent">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text="Distância: "
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"
                    android:textStyle="bold"/>

                <TextView
                    android:id="@id/txtDescricao"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text=""
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"/>
            </TableRow>

            <TableRow
                android:id="@id/tableRow3"
                android:layout_height="fill_parent">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text="Endereço:"
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"
                    android:textStyle="bold"/>

                <TextView
                    android:id="@id/txtEndereco"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="2.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text=""
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"/>
            </TableRow>

            <TableRow
                android:id="@id/tableRow4"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text="Valor: "
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"
                    android:textStyle="bold"/>

                <TextView
                    android:id="@id/txtValor"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text="R$ 0,00"
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"/>
            </TableRow>

            <TableRow
                android:id="@id/tableRow5"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text="Telefone: "
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"
                    android:textStyle="bold"/>

                <TextView
                    android:id="@id/txtPtoReferencia"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.0"
                    android:autoLink="phone"
                    android:background="@drawable/tabela_conteudo"
                    android:paddingLeft="3.0dip"
                    android:text=""
                    android:textAppearance="?android:textAppearanceMedium"
                    android:textColor="#ff000000"/>
            </TableRow>
        </TableLayout>

        <ListView
            android:id="@+id/pedidos_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></ListView>

        <Button
            android:id="@id/btnAceitar"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_green"
            android:text="Aceitar"/>

        <Button
            android:id="@id/btnVerMapa"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_blue"
            android:text="Ver Mapa"/>

        <Button
            android:id="@id/btnVerOrigemWaze"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_blue"
            android:text="Ver Local Origem"/>

        <Button
            android:id="@id/btnVerDestinoWaze"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_blue"
            android:text="Ver Local Destino"/>

        <Button
            android:id="@id/btnInformarTmpEstimado"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_blue"
            android:text="Tempo Estimado"/>

        <Button
            android:id="@id/btnClienteBordo"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_blue"
            android:text="Produto Já Recolhido"/>

        <Button
            android:id="@id/btnInformarValor"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_blue"
            android:text="Informar Valor"/>

        <Button
            android:id="@id/btnRejeitar"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_red"
            android:text="Rejeitar"/>

        <Button
            android:id="@id/btnCancelarAposAceitar"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_red"
            android:text="Cancelar Corrida"
            android:visibility="invisible"/>

        <Button
            android:id="@id/btnFinalizar"
            style="@style/ButtonText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_blue"
            android:text="Finalizar Corrida"
            android:visibility="invisible"/>
    </LinearLayout>
</ScrollView>

屏幕显示如下: http://anstaxi.com.br/android-screen-current-wrong.png

我需要显示所有项目。

代码段为:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tela_corrida_multiponto);

String[] mobileArray =     {"Android","IPhone","WindowsMobile","Blackberry","WebOS","Ubuntu","Windows7","Max     OS X"};

        ArrayAdapter adapter = new ArrayAdapter<String>(this,     R.layout.activity_listview_pedidos, mobileArray);

        ListView listView = (ListView) findViewById(R.id.pedidos_list);
        listView.setAdapter(adapter);
}

-

2 个答案:

答案 0 :(得分:0)

您的问题是在scrollview中使用listview。 Listview无法在scrollview中进行streatch。

解决了这个问题。你会遇到滚动问题(滚动哪一个?)

但是这个链接解决了你的问题:

Android list view inside a scroll view

答案 1 :(得分:0)

您的问题是ScrollView中的ListView,因此您在触摸ListView时可以实现触摸侦听器。

ListView lv = (ListView) findViewById(R.id.layout_lv);
lv.setOnTouchListener(new OnTouchListener() {
    // Setting on Touch Listener for handling the touch inside ScrollView
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    // Disallow the touch request for parent scroll on touch of child view
    v.getParent().requestDisallowInterceptTouchEvent(true);
    return false;
    }
});