How to launch an Activity on ListView Item click android

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to launch an Activity on ListView Item click android

Postby sajiddesigner » Sun May 05, 2013 8:51 am

hello
I am new to android application development and i am developing and application for learning purpose.
Can any body please help me in creating an activity that launch and activity on ListView Item Click.

I am using Following code for Populating Listview Items.
filename: activity_menu.java

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.my.android.app;
  3.  
  4.  
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import android.app.Activity;
  9. import android.app.LauncherActivity.ListItem;
  10. import android.content.Intent;
  11. import android.os.Bundle;
  12. import android.view.View;
  13. import android.widget.AdapterView;
  14. import android.widget.ListView;
  15. import android.widget.SimpleAdapter;
  16.  
  17. public class activity_menu extends Activity {
  18.        
  19.         String[] countries = new String[] {
  20.             "Contacts",
  21.             "SMS",
  22.             "Files & Photos",
  23.             "Prefrences",
  24.             "Logout",
  25.  
  26.     };
  27.    
  28.     // Array of integers points to images stored in /res/drawable-ldpi/
  29.     int[] flags = new int[]{
  30.                 R.drawable.phonebook,
  31.                 R.drawable.sms,
  32.                 R.drawable.filesphotos,
  33.                 R.drawable.settings,
  34.                 R.drawable.key,
  35.  
  36.     };
  37.        
  38.     // Array of strings to store currencies
  39.     String[] currency = new String[]{
  40.         "Manage Contacts Backup",
  41.         "Manage SMS Backup",
  42.         "Manage files & Photos Backup",
  43.         "Set your prefrences",
  44.         "Logout of Application",
  45.  
  46.     };
  47.        
  48.         protected void onCreate(Bundle savedInstanceState) {
  49.                 super.onCreate(savedInstanceState);
  50.                 setContentView(R.layout.activity_menu);        
  51.                  // Each row in the list stores country name, currency and flag
  52.         List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
  53.         for(int i=0;i<5;i++){
  54.                 HashMap<String, String> hm = new HashMap<String,String>();
  55.             hm.put("txt", countries[i]);
  56.             hm.put("cur", currency[i]);
  57.             hm.put("flag", Integer.toString(flags[i]) );            
  58.             aList.add(hm);  
  59.  
  60.         }        
  61.         // Keys used in Hashmap
  62.         String[] from = { "flag","txt","cur" };        
  63.         // Ids of views in listview_layout
  64.         int[] to = { R.id.flag,R.id.txt,R.id.cur};
  65.         // Instantiating an adapter to store each items
  66.         // R.layout.listview_layout defines the layout of each item
  67.         SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
  68.         // Getting a reference to listview of main.xml layout file
  69.         ListView listView = ( ListView ) findViewById(R.id.listview);
  70.         // Setting the adapter to the listView
  71.         listView.setAdapter(adapter);  
  72.        
  73.         }      
  74. }
  75.  
Parsed in 0.042 seconds, using GeSHi 1.0.8.4



Please help on this. waiting for Responses.
sajiddesigner
Once Poster
Once Poster
 
Posts: 1
Joined: Sun May 05, 2013 8:45 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests