Hi all,

I thought of asking for some more guidance. So basically i am not able
to open the a new screen from a button click. I followed some
tutorials and basically they take you from scratch how to make a new
page working, whereas in my case there is a part of code which is
there and being a novice java learner i am sort of confused how I can
make the new page working on this button click.

Here are the two screenshots of the problem i am facing. I understand
that my class Hellolistview is alaerdy defined but I am not able to
understand what should be the replacment for that class when it comes
to this error i am facing. My activity name itself is hello list view
so I don't understand why this is creating problem? Should I have a
different activity name than the name of the class?

http://www.flickr.com/photos/34403...@n02/5073068252/in/photostream/
http://www.flickr.com/photos/34403...@n02/5073071490/in/photostream/

Here is the complete code

package com.varun.HelloListView;

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

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
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>> bottom= 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});



                //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();
                                }
                  }
                );


        }


        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();
                }

        }

        @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 "
        };
}

public class HelloListView extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button mainNext = (Button) findViewById(R.id.Button5);
        mainNext.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent i = new Intent(HelloListView.this,
screen2.class);
                startActivity(i);
            }
        });

    }
}


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

Reply via email to