0
所以我有一个看起来像这样的片段观点:Android Studio,如何使用数组或光标的数据填充自定义ListView?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivityFragment"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">
//Various elements
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/notes_list_view"
android:drawSelectorOnTop="false">
</ListView>
</LinearLayout>
所以ListView控件是一组元素的底部。我一直在试图弄清楚如何在这个列表视图中填充项目,但无论我尝试什么,我都无法获得任何显示在数组中的内容,每次都是空的。理想情况下,我想填补,看起来像这样的项目视图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal">
<FrameLayout
android:layout_width="60dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/list_item_icon"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="7"
android:orientation="vertical">
<TextView
android:id="@+id/list_item_1_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textSize="20sp"/>
<TextView
android:id="@+id/list_item_2_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:textAppearanceSmall"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/list_item_3_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:textAppearanceLarge"/>
<TextView
android:id="@+id/list_item_4_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:textAppearanceSmall"/>
</LinearLayout>
</LinearLayout>
有人可以帮我写一个ArrayAdapter或CursorAdapter的只是使事情出现,我以后可以调整它,我打算这样做反正因为数据最终将来自数据库。
另外,有人可以找到什么是没有什么可以显示,我没有经验的UI设计,我担心我只是有空间的列表视图被阻止。
作为参考,我使用的11
与'SimpleCursorAdapter'你不需要写任何东西,但适配器的构造函数(也没有必要遍历分贝'Cursor'),并请**不要**在回答使用'像ArrayAdapter'你接受,它是** NOT **你应该遵循的方式,如果你的数据来自sqlite数据库 – pskink