Reputation: 77
I want to pass two values to intent by using bundle, but the value is not passing when I click the intent. Below is the source code for this:
public static final String ID_EXTRA = "com.example._ID";
protected static final String ID_LISTID = "com.example._ID";
String list = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
list = getIntent().getStringExtra(main.ID_EXTRA);
listView = (ListView) findViewById(R.id.productList);
{
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
myid = (int) id;
}
});
}
==============================================================================
Bundle bundle = new Bundle();
bundle.putString(ID_EXTRA, String.valueOf(myid));
bundle.putString(ID_LISTID, list);
editProduct.putExtras(bundle);
startActivity(editProduct);
Upvotes: 0
Views: 217
Reputation: 19790
Nobody can answer this question without providing extra data:
They should not be the same! You have supplied both the same values. Change this to something like "com.example._ID1
" and "com.example._ID2
".
Upvotes: 0
Reputation: 157437
Bundle
is built upon HashMap
, using the same key in order to store value will cause last element you put to me replaced with the item you are inserting. Use different keys:
For instance:
public static final String ID_EXTRA = "com.example._ID2";
protected static final String ID_LISTID = "com.example._ID1";
Upvotes: 2