我有一个 ListView,其中包含来自已解析 JSON 的数据。所以这是我的示例代码:
ArrayList<HashMap<String, String>> myList = new ArrayList<HashMap<String, String>>();
/**
* parsing JSON...
* ...
* ...
* ...
*/
ListAdapter adapter = new SimpleAdapter(this, myList, R.layout.s_layout, new String[]{NAME, TEXT}, new int[]{R.id.name, R.id.text});
setListAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
String inName = ((TextView) view.findViewById(R.id.name)).getText().toString();
String inText = ((TextView) view.findViewById(R.id.text)).getText().toString();
Intent intent = new Intent(getApplicationContext(), StaffProfileActivity.class);
intent.putExtra("staff_name", inName);
intent.putExtra("staff_desc", inText);
startActivity(intent);
}
});
我的问题是我如何在不使用的情况下将数据传递给 Intent
String inName = ((TextView) view.findViewById(R.id.name)).getText().toString();
我的意思是,如何从我的 ListView 中获取我的数据并将其赋予意图?