我可以在 Android 上使用带有文本视图的列表视图和图像图标吗

2024-05-05

我需要一个像下面的 Android 应用程序那样的列表视图

由于我无法发布图片,所以应该是这样的


图片在这里 |一些自由文本 |用户名等


这是你的任务


任务1>

任务2>


任务 1 和任务 2 是将从数据库动态获取的列表

我试图拥有一个带有文本视图的列表,问题是我只能获取列表或文本视图,而不能同时获取列表或文本视图,我什至尝试过相对布局,在这种情况下,我看到文本重叠

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/g_tracker_layout" 
     android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">  

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                        android:id="@+id/question1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:autoLink="all"
                        android:text="@string/question1"
                        /> 
   <ListView android:id="@+id/ListView01"
 android:layout_width="match_parent"
 android:layout_height="match_parent" />


</LinearLayout>

任何帮助指导对于实现与此类似的布局都非常有帮助

以下是 onCreateMethod() 中的片段

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.g_tracker_home); 
        this.dh = new TrackerDAO(this); 
        lv1=(ListView)findViewById(R.id.ListView01); 
        trackerObj = dh.selectAll();
        if(trackerObj!=null) {
        List<String> al = new ArrayList<String>();
        for(Tracker obj : trackerObj ){
          al.add(obj.getTrackerName());
        }
           lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , al));
   }

这是摘录 http://commonsware.com/Android/excerpt.pdf我的一本书中展示了如何控制列表行的创建,以便您可以混合文本和图像。该摘录中描述的示例项目可以找到在这个目录下 http://github.com/commonsguy/cw-android/tree/master/FancyLists/本书的 GitHub 存储库。

简而言之,对于一个ArrayAdapter,您需要将其子类化并覆盖getView()更新文本和图像。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我可以在 Android 上使用带有文本视图的列表视图和图像图标吗 的相关文章

随机推荐