Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview和textview在同一布局中_Android_Listview - Fatal编程技术网

Android Listview和textview在同一布局中

Android Listview和textview在同一布局中,android,listview,Android,Listview,在我的应用程序中,我必须显示一个listview,在下面我必须显示一个textview。listview和textview是否可能在同一个布局中? 我的代码如下: setContentView(R.layout.report); ListView lv=(ListView)findViewById(R.id.listView1); db.open(); Cursor c = db.getAllTitles(); startManagingCurso

在我的应用程序中,我必须显示一个listview,在下面我必须显示一个textview。listview和textview是否可能在同一个布局中? 我的代码如下:

  setContentView(R.layout.report);  
     ListView lv=(ListView)findViewById(R.id.listView1);
     db.open();
     Cursor c = db.getAllTitles();
     startManagingCursor(c);    
     String[] from = new String[] { db.KEY_INCOME,db.KEY_DESC};
     int[] to = new int[] { R.id.textView1 ,R.id.textView2};
     SimpleCursorAdapter notes =
                new SimpleCursorAdapter(this, R.layout.report, c, from, to);
//     System.out.println("notes="+notes.getCount());
     lv.setAdapter(notes);
    String total=  db.add();   
实际上,我正在显示2个textview以显示列表中的数据,最后我必须添加第3个textview以显示总计,如果我放置相对布局,则此listview将正确地覆盖其中一个。我的Xml文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >   

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   />
<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   /> 
<ListView
    android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"        
    >
</ListView>  

任何人都可以帮助我。谢谢你的帮助。

是的,这是可能的,但是当列表大小超过屏幕高度时,你将永远无法看到textview。因此,不要将视图添加到LinearLayout中,而是将这些视图添加到RelativeLayout中,将ListView高度设置为填充父视图,并在文本视图的上方。和父底部文本视图的对齐方式。

您可以在屏幕底部放置文本视图,列表视图占据屏幕顶部和底部文本视图之间的整个空间

此布局应具备以下功能:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">  

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@id/textView1"/>
</RelativeLayout>

是的,您可以使用Listview下方的Textview使用布局边距底部给Listview添加一些填充,并将Textview添加到Listview下方。因此,使用RelativeLayout时,请使用Linearlayout而不是RealiveLayout,并将方向设置为垂直

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

<your textview/>
<your textview/>   

<your listview/>
<your textview with proper id/>

</LinearLayout>

是的,你能做到。你们在屏幕上显示什么?你想做什么呢?你可以像这样使用自定义适配器,因为我跟踪了你的代码。每个数据的总数都会出现。但是我想是总数应该只出现在列表的末尾。你问的是设计还是java逻辑?对于设计,只需将第三个文本视图移到listview的下面。我们无法在java代码中为您提供帮助,因为我们不知道您的确切需求。我也尝试过这样做,但它不起作用。K我将在这里解释我的场景。在我的数据库中,有一个带有cloumnamesincome的表,说明。在我的布局中,我使用2个文本视图在列表视图中显示了该数据库。我已经给出了问题中的代码。现在显示列表视图之后,我想在文本视图中显示收入列的总计,该列表视图应位于列表视图下方。现在我得到了总计,但我无法在文本视图中显示这一点。如果我使用线性布局,则表示列表视图中的每个数据都有总计。假设我使用相对布局,则数据会相互覆盖。我认为您使用的是带有2个文本视图的自定义列表。一个用于收入,另一个用于描述。现在,您希望将总收入分配给文本视图的assing,它应该位于列表视图下方。不要在report.xml文件中使用其他文本视图。只需在列表视图下创建一个文本视图,并正确获取该id,然后根据需要分配值。这对我不起作用。有人体验过此代码的成功吗?