johnk
johnk

Reputation: 77

cannot pass two value to intent

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

Answers (2)

RvdK
RvdK

Reputation: 19790

Nobody can answer this question without providing extra data:

  • What is the value of ID_EXTRA.
  • What is the value of ID_LISTID.

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".

  • myid, is suspect this is an integer. Please add it via putInt list
  • what is list? You say it is a string, but I don't really believe that. If it is, please rename your variable to something more understanding. Not only for you but also for the one who is going to use your code.

Upvotes: 0

Blackbelt
Blackbelt

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

Related Questions