簡體   English   中英

Android在同一布局xml上有一個表和按鈕

[英]Android Have a Table and buttons on the same layout xml

我有一個頁面要在其中放置表格,並在上方和下方有按鈕。 我的布局具有以下XML。 但是,即使我能解決,也行不通!

編輯:我已經更新了XML以顯示我想要實現的目標。 里面的表,但是它不會讓我通過ListView listView = (ListView) findViewById(R.id.lvLocation);

在此處輸入圖片說明

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

    <Button
        android:id="@+id/btnAdd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Add Item" />

       <ListView
           android:id="@+id/lvLocation"
           android:layout_width="match_parent"
           android:layout_height="fill_parent"
           android:layout_above="@+id/btnBack"
           android:layout_alignParentLeft="true"
           android:layout_below="@+id/btnAdd"
           android:drawSelectorOnTop="false" >

    </ListView>

    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Back" />

</RelativeLayout>

我的代碼:(刪除了Db調用和數組設置)

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


    ListView listView = (ListView) findViewById(R.id.lvLocation);
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_2, android.R.id.text1, mArrayList);

    int[] colors = {0, 0xFFFF0000, 0}; 
    listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    listView.setDividerHeight(1);
    listView.setAdapter(adapter); 

    }



}

這是我想要達到的目標。 不是顏色,只是概念:

在此處輸入圖片說明

我認為這會有所幫助

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

    <Button
        android:id="@+id/btnAdd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Add Item" />

    <TableLayout
        android:id="@+id/lvLocation"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/btnBack"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btnAdd" >

    </TableLayout>

    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Back" />

</RelativeLayout>

代替 :

ListView listView = (ListView) findViewById (R.id.lvlocation);

只需使用:

 ListView listView  = getListView();

暫無
暫無

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

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