android listview中的一行设计

时间:2013-02-18 18:59:47

标签: android listview fragment

我的Android应用程序需要帮助。我需要在listview中自定义项目。我的应用程序使用片段。我不知道如何将list_item.xml实现到我的代码中。

KartyListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.karty_list, container, false);
    return view;
}

karty_list.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="match_parent"
android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:visibility="gone" />

<TextView
    android:id="@android:id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/prazdna_db"
    android:textColor="#f00"
    android:visibility="visible" />

</LinearLayout>

我想在list_item.xml中设计一行,但我不知道如何。

2 个答案:

答案 0 :(得分:0)

Jus创建所需的布局,并将其作为要充气的视图传递给列表适配器。例如,使用SimpleAdapter

mAdapter = new SimpleAdapter(context, list, R.layout.my_custom_list_item, from, to);
mListView.setAdapter(myAdapter);

答案 1 :(得分:0)

here你可以找到一个很好的教程来构建你的列表视图..我认为它会对你有所帮助。