Listview Onitemclicklistener With A New Activity
I have a listView with an OnItemClickListener. When I am clicking on an item, I would like to open a new wiew in a new Activity like this: final ListView lv1 = (ListView) findViewB
Solution 1:
You should add it to the intent:
Intent myIntent = newIntent(v.getContext(), UserSubmissionLog.class);
myIntent.putExtra("position", position);
startActivityForResult(myIntent, 0);
and in the new Activity, call:
int prePosition = getIntent().getIntExtra("position", someDefaultIntValue);
Solution 2:
Try this,
publicclassyourClassName
{
privatestatic listIndex = 0;
......
......
final ListView lv1 = (ListView) findViewById(R.id.ListView02);
lv1.setAdapter(new SubmissionsListAdapter(this,searchResults));
lv1.setOnItemClickListener(new OnItemClickListener() {
publicvoidonItemClick(AdapterView<?> parent, View v,
int position, long id) {
listIndex = position;
Intent myIntent = new Intent(v.getContext(), UserSubmissionLog.class);
startActivityForResult(myIntent, 0);
UserSubmissionLog userSubmissionLogs= new UserSubmissionLog(position);
System.out.println("Position "+position);
}
}
);
// make new static method to access listIdex from another classprivatestaticintgetListIndex()
{
return position;
}
}
Solution 3:
Intent myIntent = newIntent(v.getContext(), UserSubmissionLog.class);
myIntent.putExtra("your_key_name_for_this_extra", position);
startActivityForResult(myIntent, 0);
And for the receiving activity, get the int value via
int receivedValue = getIntent().getIntExtra("your_key_name_for_this_extra", default_value);
Post a Comment for "Listview Onitemclicklistener With A New Activity"