Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a list view where I want an item to get clicked and display its content using XML parsing.

XML
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.students);

        ListView listView = (ListView) findViewById(R.id.listView10);
        LoginVO loginVO = LoginXMLStuff.loginVO;
        ArrayList<ChildVO> childList = loginVO.getChildVO();
        String[] childName = new String[childList.size()];
        for (int i = 0; i < childList.size(); i++) {

            childName[i] = childList.get(i).getFirstName() + " "
                    + childList.get(i).getLastName();
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1,
                childName);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Toast.makeText(getApplicationContext(),
                        "This is the " + position + " student",
                        Toast.LENGTH_LONG).show(); [ "value of position" from here to below activity]

                Intent reminder = new Intent(DisplayListForChild.this,
                        ReminderActivity.class);
                reminder.putExtra("pos", position);
                startActivity(reminder);
            }

        });
    }
}




Now how do I get reference to position in another activity which is this

public class ReminderActivity extends Activity implements OnClickListener {

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.listview_screen);

		String logged = LoginXMLStuff.loginVO.getApplicationUserID();
		String userType = LoginXMLStuff.loginVO.getUserType();
		String userId = null;
		if (userType.equalsIgnoreCase("Parent")) {
		
        userId = LoginXMLStuff.loginVO.getChildVO().get(position).getUserId(); [ Here in get(position ) how to reference and get value of position from above activity?]
		} else if (userType.equalsIgnoreCase("Student")) {
			userId = logged;
		}


Its urgent please help.
Thank you.
Posted

To access the position I used this part of code. Initialize with 0 and call the Intent of previous class.

int position = getIntent().getIntExtra("pos", 0);
 
Share this answer
 
v2
To access the position I used this part of code. Initialize with 0 and call the Intent of previous class.
int position = getIntent().getIntExtra("pos", 0);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900