views:

96

answers:

3

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));
   }
A: 

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.

CommonsWare
Thanks for the quick response I did went through the expert of your book for creating a list from an Array and it was quiet helpful Problem is on the screen I want to have a have a LIST displayed along with other components and I am extending the Activity class instead of extending ListActivity
Ameya Thakur
A: 

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.

Cristian
Let me try that real quickly
Ameya Thakur
I am having the same problem as the text is overlaying with the list and somehow cannot figure it out
Ameya Thakur
A: 

Well thanks for the people who responded here is the solution which i found from the following site

http://www.androidpeople.com/android-custom-listview-tutorial-example/comment-page-1/#comment-685

This was very neat and exactly what i wanted

Ameya Thakur