Psssing keys for each value in a list view to another view

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

Psssing keys for each value in a list view to another view

Postby anurahim » Mon Dec 01, 2008 4:39 pm

hi,

I have a list view to list some categories. I need to list the products under each category in a new list. I used arrayList to the adapter, I am able to list the category names . but I cant pass the keys (categoryIds) to the next view for getting the products.
Please help me in this regard.

For Now I am trying to display the categoryId in the produts page, but i am not suceeding :(


the following is the code I tried

public class Categories extends ListActivity {

ArrayList CatList ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CatList= GetCategories(); // this returns an Array List
setContentView(R.layout.categories);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,CatList));


}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// Map map = (Map) l.getItemAtPosition(position);

// Intent intent = (Intent) map.get("intent");
// startActivity(intent);
// super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, Products.class);
// startActivity(i);
i.putExtra("categ",CatList.get(position).toString() );
startActivity(i);
// setContentView(R.layout.products);
}
public static Arraylist GetCategories() {
code to get the array List
}
}
/// following is the products.java


public class Products extends ListActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.products);
TextView CategoryIdtext = (TextView) findViewById(R.id.CategoryId);
Bundle extras = getIntent().getExtras();
CategoryIdtext.setText("CAtegoryID:"+extras.getString("categ"));
}
anur
anurahim
Junior Developer
Junior Developer
 
Posts: 24
Joined: Fri Jun 27, 2008 11:26 am

Top

Postby dkkundudolan » Wed Dec 17, 2008 7:47 am

Hi all,

I also got the same prob.
can anybody tell me the suuestions?

Thanks.
dkkundudolan
Experienced Developer
Experienced Developer
 
Posts: 83
Joined: Mon Mar 03, 2008 12:50 pm

Postby haden » Thu Dec 18, 2008 2:50 pm

Do you get any errors?
haden
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Thu Sep 11, 2008 11:51 am

Postby dkkundudolan » Fri Dec 19, 2008 6:40 am

Hi haden,

I am not getting any errors. program is running. But heading is not displaying in the next screen.
My prob is: I have 16 items in a list. When i will click on the Item, and it will move to the next screen. In the next screen, the heading will display which item i selected.

Can you give suggestions........

Thanks.
dkkundudolan
Experienced Developer
Experienced Developer
 
Posts: 83
Joined: Mon Mar 03, 2008 12:50 pm

Postby haden » Sat Dec 20, 2008 12:22 am

dkkundudolan wrote:Hi haden,

I am not getting any errors. program is running. But heading is not displaying in the next screen.
My prob is: I have 16 items in a list. When i will click on the Item, and it will move to the next screen. In the next screen, the heading will display which item i selected.

Can you give suggestions........

Thanks.


Can you send me your code?
haden
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Thu Sep 11, 2008 11:51 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests