如何在另一个活动中获取职位参考 [英] How to get the position reference in another activity

查看:50
本文介绍了如何在另一个活动中获取职位参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,我希望在其中单击项目并使用XML解析显示其内容.

I have a list view where I want an item to get clicked and display its content using XML parsing.

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.

推荐答案

要访问该位置,我使用了这部分代码.初始化为0并调用上一类的Intent.

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);


要访问该位置,我使用了这部分代码.初始化为0并调用上一类的Intent.
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);


这篇关于如何在另一个活动中获取职位参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆