簡體   English   中英

如何在列表視圖中顯示所有項目

[英]how to display all items in the listview

我正在嘗試在我的應用程序中已經存在的屏幕上包括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);
}

--

您的問題是在滾動視圖內使用列表視圖。 Listview不能在scrollview中拖拉自身。

並且解決了這個問題。 您將在滾動時遇到問題(要滾動哪個?)

但是此鏈接解決了您的問題:

滾動視圖內的Android列表視圖

您的問題是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;
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM