I am sending a listview clicked item id to another activity using intents putExtra and get the value in activity using getIntent(). I click a name on Listview it gives me the detail about previously adding a member. Not gives me the detail about clicked name person.

My listview activity.

        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,result);
        listContent.setAdapter(adapter);
        listContent.setTextFilterEnabled(true);

        c.close();

        listContent.setOnItemClickListener(this);
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        Intent myIntent = new Intent(Activity.this, details.class);
        myIntent.putExtra("id", id);
        startActivity(myIntent);
    }

This is my Second activity.

 @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);

    int value= getIntent().getIntExtra("id",0);

I expect that when I click on a name in listview it gives me the details of the same name on the second activity. But this code gives me the details of the person who placed in listview above clicked name. Thanks

1 Answers

-1
Zuhrain On

Try this.

 adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,result);
        listContent.setAdapter(adapter);
        listContent.setTextFilterEnabled(true);

        c.close();

        listContent.setOnItemClickListener(this);
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        Intent myIntent = new Intent(Activity.this, details.class);
        myIntent.putExtra("id", id);
        startActivities(new Intent[]{myIntent});
    }

Second activity.

 private int value;

 @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        Intent intent = getIntent();
        if (intent.getExtras() != null) {
            value = intent.getExtras().getInt("id");
        }
    }