I am trying to make a list view with two rows and two columns in each
element of the list view. The code I have so far I am trying to
achieve the first task i.e. two rows inside a single list view item. I
saw some online tutorial, and I formed a text view which I inflated in
the java file. It works but it's not exactly what i want, I guess
instead of the last digit which is displayed presently in the list
view, I would like to know how to hard code text 1, text 2, text 3
etc.These text 1 , 2, 3 are basically locations. Is my description
comprehensible?

Here is the updated code.

package com.varun.HelloListView;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class HelloListView extends ListActivity {
        TextView selection;

        ArrayList<HashMap<String, String>> list1 = new
ArrayList<HashMap<String, String>>();
        SimpleAdapter smipleAdapter1;

        ArrayList<HashMap<String, String>> list2 = new
ArrayList<HashMap<String, String>>();
        SimpleAdapter smipleAdapter2;

        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);

                setContentView(R.layout.main);


                smipleAdapter1 = new SimpleAdapter(this,
                                                                                
  list1,
                                                                                
  R.layout.list_item,
                                                                                
  new String[] {"line1", "line2"},
                                                                                
  new int[] {R.id.label1, R.id.label2});
                smipleAdapter2 = new SimpleAdapter(this,
                                                                                
  list2,
                                                                                
  R.layout.list_item,
                                                                                
  new String[] {"line1", "line2"},
                                                                                
  new int[] {R.id.label1, R.id.label2});

                //pupulate the lists
                addItems();

                this.setListAdapter(smipleAdapter1);

                // button click
                Button next1 = (Button) findViewById(R.id.Button1);
                next1.setOnClickListener(
                new View.OnClickListener() {
                        public void onClick(View view) {
                                        setListAdapter(smipleAdapter1);
                                        smipleAdapter1.notifyDataSetChanged();
                        }
        }
        );

                Button next2 = (Button) findViewById(R.id.Button2);
                next2.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view) {
                                        setListAdapter(smipleAdapter2);
                                        smipleAdapter2.notifyDataSetChanged();
                                }
                  }
                );

                /*

                setListAdapter(a1);

                myActivity = this;
                Button next1 = (Button) findViewById(R.id.Button1);
                next1.setOnClickListener(
                new View.OnClickListener() {
                        public void onClick(View view) {
                                        myActivity.setListAdapter(a1);
                                        a1.notifyDataSetChanged();
                        }
        }
        );

                //setListAdapter(a2);
                myActivity = this;
                Button next2 = (Button) findViewById(R.id.Button2);
                next2.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view) {
                                        myActivity.setListAdapter(a2);
                                        a2.notifyDataSetChanged();
                                }
                  }
                );

                //setListAdapter(a3);
                //myActivity = this;
                Button next3 = (Button) findViewById(R.id.Button3);
                next3.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view) {
                                        myActivity.setListAdapter(a3);
                                        a3.notifyDataSetChanged();

                                }
                        }
                );

    //setListAdapter(a4);
        //myActivity = this;
        Button next4 = (Button) findViewById(R.id.Button4);
        next4.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view4) {
                                        myActivity.setListAdapter(a4);
                                        a4.notifyDataSetChanged();
                                }
                        }
        );
       */
        }

        private void addItems() {
                long ts = System.currentTimeMillis();
                int lastDigit = (int)( ts % 10 );

                for(int i = 0; i < AndroidPhones1.length; i++) {
                        HashMap<String,String> item = new 
HashMap<String,String>();
                        item.put( "line1", AndroidPhones1[i] );
                        item.put( "line2", "lastDigit: "+Integer.toString( 
lastDigit ) );
                        list1.add( item );
                        smipleAdapter1.notifyDataSetChanged();
                }

                for(int i = 0; i < AndroidPhones2.length; i++) {
                        HashMap<String,String> item = new 
HashMap<String,String>();
                        item.put( "line1", AndroidPhones2[i] );
                        item.put( "line2", "lastDigit: "+Integer.toString( 
lastDigit ) );
                        list2.add( item );
                        smipleAdapter1.notifyDataSetChanged();
                }
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                super.onCreateOptionsMenu(menu);

                menu.add(0, Settings.ENTER_FOOD, 0, "Enter Food");
                menu.add(0, Settings.ANALYZE_FOOD, 0, "Analyze Food");
                menu.add(0, Settings.SETTINGS, 0, "Settings");

                return true;
        }


        static final String[] AndroidPhones1 = new String[] {
                "HTC Evo 1G",  "Google Nexus One", "Motorola Devour",
                "Motorola CLIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };

        static final String[] AndroidPhones2 = new String[] {
                "HTC Evo 2G",  "Google Nexus One", "Motorola Devour",
                "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };

        static final String[] AndroidPhones3 = new String[] {
                "HTC Evo 3G",  "Google One", "Motorola Devour",
                "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };

        static final String[] AndroidPhones4 = new String[] {
                "HTC Evo 4G",  "Google Nexus hello", "Motorola Devour",
                "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };
        }



On Oct 5, 4:30 pm, TreKing <[email protected]> wrote:
> On Tue, Oct 5, 2010 at 3:56 PM, Varun Khanduja <[email protected]>wrote:
>
> > I am trying to get two lines in the same row in a list view and I looked at
> > some things online but found it hard to apply to what I am trying to
> > achieve.
>
> What are you trying to achieve? What's not working thus far?
>
> --------------------------------------------------------------------------- 
> ----------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to