onListItemClick with Mulitple Value

Put your problem here if it does not fit any of the other categories.

onListItemClick with Mulitple Value

Postby Juniorflip » Fri May 21, 2010 2:12 pm

Hello, I am trying to find some assistance on the arrayadapter I am using. If I am using the wrong one please let me know. I have an xml document parser that output the detail into a 2 string field.
RowDetail is the description
Code: Select all
RowDetail =  "Date: " + strDate ;

RowDetailValue is the value I want to send to the next intent
Code: Select all
RowDetailValue = strRowDetailValue; //example 65


Below is the snippet of code that matter, for the arrayadapter
Code: Select all
ArrayList <HashMap<String,String>>RowDetailList = new ArrayList<HashMap<String,String>>();
HashMap<String,String> temp = new HashMap<String,String>();
temp.put(RowDetail,RowDetailValue);
RowDetailList.add(temp);

ArrayAdapter<HashMap<String,Temp>> FinalRowDetailList = new ArrayAdapter<HashMap<String,String>>(this,
    R.layout.newsfeed, RowDetailList);

this.setListAdapter(FinalRowDetailList);


For all intent purposes I am assuming that the hash map is allow for adding a second value to the array similar the the HTML < Option Value = 64 >05/20/10</option>. If I am right about the hashmap here is my onListItemClick
Code: Select all
public void onListItemClick(ListView l, View v, int position, long id){
     super.onListItemClick(l, v, position, id);
     
     // Get the item that was clicked
     Object o = this.getListAdapter().getItem(FinalRowDetailList.RowDetailList);//Obvious Broken part
     String rowid = o.toString();
     Integer startvalue = (Integer.parseInt(rowid));

     
     
     String finalvalue = (new Integer(startvalue)).toString();


     
     // Create an VIEW intent
     Intent intent = new Intent(NewsFeed.this, NewsFeedDetail.class);
     intent.putExtra("newmValue", finalvalue);
     startActivity(intent);
    }
   
Juniorflip
Freshman
Freshman
 
Posts: 2
Joined: Fri May 21, 2010 1:50 pm

Top

Re: onListItemClick with Mulitple Value

Postby Juniorflip » Fri May 21, 2010 8:37 pm

So I am still messing with this and I am trying a new route... But I still cannot get the Value value

The end goal is if I click on Yasmin, txHomeTeam should display 8

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.util.ArrayList;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.AdapterView;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.ListView;
  8. import android.widget.TextView;
  9. import android.widget.AdapterView.OnItemClickListener;
  10.  
  11. public class lister extends Activity {
  12.     /** Called when the activity is first created. */
  13.         TextView txHomeTeam;
  14.         protected ListView mFavlist;
  15.         protected ArrayList<Favorite> fakeFavs = new ArrayList<Favorite>();
  16.  
  17. @Override
  18.     public void onCreate(Bundle icicle) {
  19.         super.onCreate(icicle);
  20.        this.setContentView(R.layout.main);
  21.  
  22.  
  23.         this.txHomeTeam = (TextView)this.findViewById(R.id.title);
  24.        
  25.         fakeFavs.add(new Favorite("John", "1"));
  26.         fakeFavs.add(new Favorite("Yasmin", "8"));
  27.         fakeFavs.add(new Favorite("Jack", "10"));
  28.        
  29.         //this.mFavlist = (ListView) this.findViewById(R.id.list_favorites);
  30.         this.mFavlist = (ListView) this.findViewById(R.id.list_favorites);
  31.         initListView();
  32.        
  33.         mFavlist.setTextFilterEnabled(true);
  34.        
  35.         mFavlist.setOnItemClickListener(new OnItemClickListener() {
  36.                         @Override
  37.                         public void onItemClick(AdapterView arg0, View view,
  38.                                            int position, long id) {
  39.                                
  40.                                 // user clicked a list item, and read the value.
  41.                                 //txHomeTeam.setText=????
  42.                                
  43.                                 }
  44.  
  45.         });
  46.  
  47.     }
  48.  
  49.    public void refreshFavListItems() {
  50.             mFavlist.setAdapter(new ArrayAdapter<Favorite>(this,
  51.                             android.R.layout.simple_list_item_1, fakeFavs));
  52.     }
  53.  
  54.     public void initListView() {
  55.         /* Loads the items to the ListView. */
  56.         refreshFavListItems();
  57.        
  58.     }
  59. protected class Favorite {
  60.         protected String Detail;
  61.         protected String value;
  62.        
  63.         protected Favorite(String Detail, String value) {
  64.                 this.Detail = Detail;
  65.                 this.value = value;
  66.                
  67.         }
  68.         public String toString() {
  69.                 return Detail;
  70.         }
  71. }
  72.  
  73.  
  74. }
  75.  
  76.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4
Juniorflip
Freshman
Freshman
 
Posts: 2
Joined: Fri May 21, 2010 1:50 pm

Re: onListItemClick with Mulitple Value

Postby fbarnard » Tue Jun 15, 2010 3:31 pm

hi

something like this

if you have a ListActivity
Code: Select all
protected void onListItemClick(ListView l, View v, int position, long id)
{
Favorite  obj = (Favorite) l.getItemAtPosition(position);   
}



or if you have a listview in the activity

Code: Select all
public void onItemClick(AdapterView arg0, View view, int position, long id)
{
   Favorite  obj = (Favorite) l.getItemAtPosition(position);   
}
fbarnard
Developer
Developer
 
Posts: 44
Joined: Tue Jun 15, 2010 12:31 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests