Start new activity on item click in listview

Quickly share your Android Code Snippets here...

Start new activity on item click in listview

Postby durgasanju » Mon Jun 07, 2010 6:06 am

HI,

I need to start an activity when we click on an item in list view. Also the items in listview must be fetched from servlet when the application is launched.
durgasanju
Freshman
Freshman
 
Posts: 3
Joined: Tue Jun 01, 2010 7:31 am

Top

Re: Start new activity on item click in listview

Postby hooked82 » Wed Mar 09, 2011 3:54 am

Take a look at the Android Dev Guide for launching an activity:
http://developer.android.com/guide/topi ... AnActivity
hooked82
Freshman
Freshman
 
Posts: 7
Joined: Sun Mar 06, 2011 11:38 pm

Re: Start new activity on item click in listview

Postby vhalexxs » Tue Mar 15, 2011 3:05 am

below is also a snippets for your reference,

Code: Select all
listview1 = (ListView) findViewById(R.id.listview1);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.items, android.R.layout.simple_list_item_1);
        adapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
        listview1.setAdapter(adapter);
       
        listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
       
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if(position == 1) {
        Intent intent = new Intent(getApplicationContext(), Activity2.class);
        startActivity(intent);
        }
        }
});


Hope this could help you
Alex Escobar
Senior Android Engineer
-----------------------
Airpush.com: The Push Notification Ad Network
User avatar
vhalexxs
Developer
Developer
 
Posts: 28
Joined: Mon Mar 14, 2011 3:19 am

Re: Start new activity on item click in listview

Postby Mike.Adams » Wed Apr 06, 2011 5:08 pm

good references :D
Hi I'm Mike. Checkout my source code, projects and work here and let me know what you think.

Feel free to also upload and submit your code/projects there for all to see and find!
Mike.Adams
Developer
Developer
 
Posts: 26
Joined: Mon Mar 07, 2011 9:19 pm
Location: New York

Re: Start new activity on item click in listview

Postby uxc.wilis » Mon Jun 20, 2011 5:30 am

great tutorials,, i can learn from this..

good reference..

thx.
uxc.wilis
uxc.wilis
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 30, 2010 3:22 pm

Re: Start new activity on item click in listview

Postby freemovietag » Sat Aug 20, 2011 8:31 pm

i buy recent a new apple iPhone...thanks for these tutorials.
freemovietag
Freshman
Freshman
 
Posts: 2
Joined: Sat Aug 20, 2011 8:22 pm

Top

Re: Start new activity on item click in listview

Postby silentkratos » Wed Dec 21, 2011 8:15 pm

I tried the method provided above to call a new activity... but it gives me an error and i have to terminate the application forcefully...

the code for my new activity is:
Code: Select all

package com.Project;

import android.app.Activity;
import android.os.Bundle;


public class Annotate extends Activity{
   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


and for the calling activity is:
Code: Select all
package com.Project;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.view.View;

public class MainMenu extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ListView lv=(ListView)findViewById(R.id.listView1);
        lv.setOnItemClickListener(new OnItemClickListener() {
           public void onItemClick(AdapterView<?> parent, View view,int position, long id)
           {
              switch( position )
               {
                  case 1:  Intent newActivity = new Intent(MainMenu.this,Annotate.class);     
                           startActivity(newActivity);
                           break;
               }
           }
        });
    }
    @Override
    protected void onPause() {
        super.onPause();
        // Another activity is taking focus (this activity is about to be "paused").
    }

}


i don't know where i go wrong...
the error states that the application unexpected error...please help... i read books too, but they just give the way to call.. what about the called activity...
silentkratos
Freshman
Freshman
 
Posts: 4
Joined: Tue Aug 02, 2011 6:20 pm

Re: Start new activity on item click in listview

Postby loosi007 » Mon Jan 02, 2012 3:56 pm

great tutorials,, i can learn from this..

good reference..


thanks
loosi007
Freshman
Freshman
 
Posts: 6
Joined: Sun Jan 01, 2012 3:29 pm

Re: Start new activity on item click in listview

Postby Squarestream » Mon Jan 02, 2012 5:07 pm

When does the app crash? At first start or when you click on a listitem?
Squarestream
Freshman
Freshman
 
Posts: 7
Joined: Tue Nov 08, 2011 10:41 am

Re: Start new activity on item click in listview

Postby hgft » Wed Feb 29, 2012 9:07 am

Coach Outlet Online Sale is with imperfections which consist of cuts, scars, and scratches will exist, the grain in its organically grown problem has between one of the most considerable dietary fibers strength, and getting a last end result between one of the most considerable durability. The grain also has organically grown breathability, resulting in increased comfort using the path from the wearer.

Louis Vuitton Outlet could possibly be one of the most well-known is not necessarily one of the most ideal for you! possibly the most current quarter round shoulder bag with fluorescent color provides you a shine in the moment, desire to possess the urge to it immediately; But possibly your pores and skin color could possibly be the earth beside the handbag could possibly be one of the most make you fondle admiringly joker choice.

Louis Vuitton Outlet supply reduce, the weakening from the role, tiny haystack in slender whole body once more and again. the right way to purchase Louis Vuitton bags That's between the powerful cohesion when Cunningham lancelet find yourself isolated point, allow wind and bad weather insulation, yr pursuing year, pile of grass system earlier short increased grass blanketed with it or bi erosion.

Jennifer Garner and Ben Affleck are the proud parents of a newborn son! The 39-year-old actress gave birth to the couple's third child in Santa Monica, Calif., a source tells Us Weekly. The family's newest addition joins older sisters Violet, 6, and Seraphina, 3. “I would have thought [Ben] wanted a boy]. At first … I really thought so,” Jen, who kept the baby's gender under wraps, told Jay Leno last month.
hgft
Experienced Developer
Experienced Developer
 
Posts: 66
Joined: Tue Feb 28, 2012 9:11 am

Re: Start new activity on item click in listview

Postby aguswgs » Tue Mar 20, 2012 11:01 am

Thanks for the code.. this helpful for me :D
aguswgs
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue Mar 20, 2012 10:08 am
Location: indonesian

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 4 guests