由於我是Android新手,我正在努力設計一個自定義佈局,它將成爲我的列表視圖行。我喜歡我的列表視圖行應該包含標題描述,細節和頁腳。我的列表視圖行保存着數據,例如我附加的圖像。請參閱附件圖片Android ListView定製(標題,描述,詳細信息,頁腳)
0
A
回答
2
你必須要創建your_layout_row.xml先
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_margin="14dp"
>
<LinearLayout
android:layout_width="60dp"
android:layout_height="60dp"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:paddingLeft="10dp"
android:layout_height="60dp"
/>
</LinearLayout>
<TextView
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:paddingRight="5dp"
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="TextView"
android:textStyle="normal|italic"
android:textSize="17dp" />
</LinearLayout>
現在在這裏你有你的列表視圖佈局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/TaskList_layout_background_color"
>
<ListView
android:id="@+id/lv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:dividerHeight="10dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
</ListView>
</RelativeLayout>
現在創建類型號
例如:
class ModelClass
{
String text;
public ModelClass(String _text)
{
text = _text;
}
public String getText()
{
return this.text;
}
}
現在在主要活動創建自定義適配器類
public class CustomAdapter extends ArrayAdapter<ModelClass> {
// declaring our ArrayList of items
private ArrayList<ModelClass> objects;
/* here we must override the constructor for ArrayAdapter
* the only variable we care about now is ArrayList<Item> objects,
* because it is the list of objects we want to display.
*/
public CustomAdapter(Context context, int textViewResourceId, ArrayList<ModelClass> objects) {
super(context, textViewResourceId, objects);
this.objects = objects;
}
/*
* we are overriding the getView method here - this is what defines how each
* list item will look.
*/
@Override
public View getView(int position, View convertView, ViewGroup parent){
// assign the view we are converting to a local variable
View v = convertView;
// first check to see if the view is null. if so, we have to inflate it.
// to inflate it basically means to render, or show, the view.
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.your_layout_row null);
}
/*
* Recall that the variable position is sent in as an argument to this method.
* The variable simply refers to the position of the current object in the list. (The ArrayAdapter
* iterates through the list we sent it)
*
* Therefore, i refers to the current Item object.
*/
ModelClass i = objects.get(position);
if (i != null) {
// This is how you obtain a reference to the TextViews.
// These TextViews are created in the XML files we defined.
TextView tt = (TextView) v.findViewById(R.id.textView);
// check to see if each individual textview is null.
// if not, assign some text!
if (tt != null){
tt.setText(objects.get(position).getText());
}
}
// the view must be returned to our activity
return v;
}
}
現在設置你的ListView適配器連接到本customAdapter。
ArrayList<MyModel> myList = new new ArrayList<MyModel>();
myList.add("1");
myList.add("2");
myList.add("3");
myList.add("4");
ListView myListView = (ListView)findViewById(R.id.lv_list);
CustomAdapter adapter= new CustomAdapter(acitivity, 0, myList);
myListView.setAdapter(adapter);
0
在這種情況下,您必須自定義適配器。
其實Relative相對更適合設計。但是現在我將使用LinearLayout編寫簡單的代碼。
這裏是ListView項的自定義佈局...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Title"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:background="@android:color/holo_green_light"
android:text="DESC"/>
<TextView
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:background="@android:color/holo_blue_light"
android:text="Other Detais"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Footer"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
</LinearLayout>
0
副本和海恩HTET修改上面的回答昂
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Title"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="20dp"
android:background="@android:color/holo_green_light"
android:text="DESC"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_weight="1"
android:gravity="center"
android:background="@android:color/holo_blue_light"
android:text="Other Detais"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="Footer"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
相關問題
- 1. Doxygen:空的詳細信息描述
- 2. Android主詳細信息詳細信息
- 3. Magento在onclick鏈接的產品詳細信息頁面打開描述標籤
- 4. Crystal Reports詳細信息詳細信息
- 5. 顯示來自ListView的詳細信息
- 6. Android ListView與詳細信息頁面null對象
- 7. MSBuild複製命令的詳細描述
- 8. 主/詳細信息頁
- 9. fullCalendar - 事件標題和詳細信息
- 10. ASP.net gridview multirow詳細信息標題
- 11. Android按鈕詳細信息
- 12. 指定詳細信息表格信息
- 13. 如何讓子類指定詳細信息,如名稱和描述
- 14. 視頻文件格式的標題信息的詳細信息
- 15. 合作伙伴頁面標題和詳細信息Crystal Report
- 16. 在php中使用標題和詳細信息插入照片標題和詳細信息
- 17. 使用帶有標題和詳細信息的recycleview的Android Cardview
- 18. 的ListView用多張頁眉和詳細信息節
- 19. 我的詳細信息表中的自定義標題
- 20. SugarCRM在詳細信息視圖中添加其他詳細信息圖標
- 21. 在產品詳細信息頁面中添加自定義Metabox(Woo-commerce產品詳細信息頁面)
- 22. 是否有可能強制Jasper報告標題,組的詳細信息和頁腳出現在同一頁上
- 23. Gridview中分頁的詳細信息
- 24. Facebook頁面詳細信息和RESTful API?
- 25. 排序詳細信息頁面MVC
- 26. 單擊圖像的詳細信息頁
- 27. 在Ios中的主詳細信息頁
- 28. 從DataList到詳細信息頁面
- 29. 網頁錯誤的詳細信息
- 30. Virtuemart 1.1產品詳細信息頁面
是頁腳,頁腳或頁腳的單元格? – NinjaCoder 2015-02-06 00:46:20
@NinjaCoder頁腳持有相應行的日期和時間 – Vrangle 2015-02-06 00:54:07
@Vrangle你有什麼試過? – iRuth 2015-02-06 01:13:08