Can I have a List view and images icon with textvi

2019-03-03 23:08发布

I need to have a listview like it is having for the following android application

Since I cannot post the image this is how it should be


INAGE Over here | Some Free text | User name etc


Here is your task


Task 1 >

Task 2 >


Task 1 & Task 2 are the list which would be dynamically picked up from the DB

I am trying to have a list with a textview the problem is that I can only get the List or the text view not both any point of time I have even tried relative layout in that case i see the text overlapping

    <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>

Any help guidance would be really helpful in achiving the layout similar to this

Following is the snippet in the 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));
   }

2条回答
淡お忘
2楼-- · 2019-03-03 23:17

Try something like this:

<RelativeLayout 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
        android:id="@+id/question1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:autoLink="all"
        android:text="@string/question1"/>
    <ListView android:id="@+id/ListView01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/question1"/>
</RelativeLayout>

I have even tried relative layout in that case i see the text overlapping

That's really nice. After you get some expertise, you will see that RelativeLayout is one of the best layout schemes. In this simple case you could use LinearLayout too, but when things start getting complex, it's better to use RelativeLayout which is really flexible and will allow you to reduce the need of nest elements.

查看更多
Lonely孤独者°
3楼-- · 2019-03-03 23:38

Here is an excerpt from one of my books showing how to take control over the creation of list rows, so you can mix text and images. The sample projects described in that excerpt can be found in this directory of the book's GitHub repository.

In a nutshell, for an ArrayAdapter, you will need to subclass it and override getView() to update both the text and the image.

查看更多
登录 后发表回答