Hello I tried taking everyone's suggestion. Still I don't think it's
working for me, can someone suggest me where I am going wrong?

package com.varun.HelloListView;

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

public class HelloListView extends ListActivity {
        TextView selection;
        ArrayAdapter a1=null;
        ArrayAdapter a2=null;
        ArrayAdapter a3=null;
        ArrayAdapter a4=null;
        ListActivity myActivity = null;
        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                a1 = new ArrayAdapter(this, R.layout.list_item,
R.id.label,AndroidPhones);
                a2 = new ArrayAdapter(this, R.layout.list_item,
R.id.label,AndroidPhones1);
                a3 = new ArrayAdapter(this, R.layout.list_item,
R.id.label,AndroidPhones2);
                a4 = new ArrayAdapter(this, R.layout.list_item,
R.id.label,AndroidPhones3);

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

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

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

                                }
                        }
                );

        setListAdapter(a4);
                myActivity = this;
                Button next3 = (Button) findViewById(R.id.Button4);
        next.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view4) {
                                        myActivity.setListAdapter(a4);
                                        a4.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[] AndroidPhones = new String[] {
                "HTC Evo 4G",  "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[] AndroidPhones1 = new String[] {
                "HTC Evo 1G",  "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[] AndroidPhones2 = new String[] {
                "HTC Evo 1G",  "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[] AndroidPhones3 = new String[] {
                "HTC Evo 1G",  "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 Sep 29, 1:34 pm, Olivier Goutet <[email protected]> wrote:
> I don't know if you can read French but there is a very good post on
> this French blog:http://android.cyrilmottier.com/?p=232
> It explain how to build a custom adapter (BaseAdapter in fact) to
> manage 2 different types of cells on a list view. I hope the source
> source code will be enough for you.
>
> The ArrayAdapter you are using is just a very simple way to display
> text cells on a listview.
>
> To display your 4 different types of items, you will need to create 4
> layout (1 for each cell type) and then inflate them in the base
> adapter (as explained in the blog).
>
> On Sep 29, 4:43 pm, TreKing <[email protected]> wrote:
>
>
>
> > On Tue, Sep 28, 2010 at 8:40 PM, Varun Khanduja 
> > <[email protected]>wrote:
>
> > > If anyone has time please try to help me out. Thanks, I looked into some
> > > examples but really found it hard to see how I can have the custom adapter
> > > runnning.
>
> > The "custom" part of an adapter is basically returning the View you want to
> > show in your list for a given item.
>
> > Currently you have the default ArrayAdapter that works on Strings. Since you
> > want something more complicated, all you have to do is create a class that
> > extends ArrayAdapter and override the getView() method to return the layouts
> > you want (as you described) based on the state of your list.
>
> > So the first thing to do is create your custom ArrayAdapter, override
> > getView, then set it as the adapter to your list and verify your views show
> > up as expected.
>
> > --------------------------------------------------------------------------- 
> > ----------------------
> > 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