I am trying to make a list view having 2 columns and within these
columns each element of list view is having two rows. I figured out
how to get two columns, one of the column is having 2 rows perfectly
but another column is not able to get the second row at all. I am not
sure whats the issue, does someone minds looking at my code and
suggesting possible issues?


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.Button;
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;

        ArrayList<HashMap<String, String>>list3 = new
ArrayList<HashMap<String, String>>();
        SimpleAdapter simpleAdapter3;


        @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});
                simpleAdapter3 = new SimpleAdapter(this,
                                                                                
        list3,
                                                                                
        R.layout.list_item,
                                                                                
        new String[] {"line3", "line4"},
                                                                                
        new int[]{R.id.label3, R.id.label4});

                //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();
                        }
        }
        );
                this.setListAdapter(smipleAdapter2);
                Button next2 = (Button) findViewById(R.id.Button2);
                next2.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view) {
                                        setListAdapter(smipleAdapter2);
                                        smipleAdapter2.notifyDataSetChanged();
                                }
                  }
                );
                this.setListAdapter(simpleAdapter3);
                Button next3 = (Button) findViewById(R.id.Button3);
                next3.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view) {
                                        setListAdapter(simpleAdapter3);
                                        simpleAdapter3.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", "varun1" );

                        list2.add( item );
                        smipleAdapter2.notifyDataSetChanged();
                }
                for(int i = 0; i < AndroidPhones3.length; i++) {
                        HashMap<String,String> item = new 
HashMap<String,String>();
                        item.put( "line3", AndroidPhones3[i] );
                        item.put( "line4", "varun3" );

                        list3.add( item );
                        simpleAdapter3.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 "
        };
        }


xml file


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=
       "http://schemas.android.com/apk/res/android";
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
                android:id="@+id/icon"
                android:layout_width="22px"
                android:paddingLeft="2px"
                android:paddingRight="2px"
                android:paddingTop="2px"
                android:layout_height="wrap_content"
                android:src="@drawable/icon"/>

        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
        <TextView
                android:id="@+id/label1"
                android:layout_width="100px"
                android:layout_height="wrap_content"
                android:textSize="10sp"/>
        <TextView
                android:id="@+id/label2"
                android:layout_width="100px"
                android:layout_height="wrap_content"
                android:textSize="10sp"/>


        </LinearLayout>

        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
        <TextView
                android:id="@+id/label3"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:layout_marginLeft="50px"
                />
        <TextView
                android:id="@+id/label4"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:layout_marginLeft="50px"
                />
        </LinearLayout>

</LinearLayout>

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