我有一個列表視圖,它被正確安排。我需要添加列標題。下面我發佈了處理listview排列的display.xml
文件。但沒有標題。Android:如何在自定義列表視圖中添加列標題
Display.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#F3CAE5"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#000"
android:text="Ser No."/>
<TextView
android:id="@+id/id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#000" />
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="#000" />
<TextView
android:id="@+id/add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="#000" />
</LinearLayout>
ListView.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/header"/>
<ListView
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</ListView>
</LinearLayout>
ShowData.java
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
/**
* Created by Akash on 3/13/2016.
*/
public class ShowData extends ListActivity {
private VivzHelper helper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
VivzHelper empClick = new VivzHelper(getApplicationContext());
Cursor cursor = empClick.getDetails();
if (cursor != null)
getListView().setAdapter(
new android.support.v4.widget.SimpleCursorAdapter(this, R.layout.display, cursor, new String[]{
"_id", "Name", "Address"
}, new int[]{R.id.id, R.id.name, R.id.add}, 0));
}
}
嘗試創建listheader.xml並使用與display.xml相同的權重,然後在代碼中設置listview.addHeaderView。 –
爲什麼不使用tableLayout與ScrollView而不是列表視圖? –