我正在尝试通过ListViewItem
单击将数据从一个活动传递到另一个活动。
但是我无法访问行内的数据,以便我可以将其传递给下一个活动。
我目前的代码是:
final ListView businessListObj = (ListView) findViewById(R.id.bussinessListView);
ListAdapter adapter = new SimpleAdapter(HomeActivity.this, bussinessList,
R.layout.business_list_item,
new String[] { TAG_NAME, TAG_ADDRESS, TAG_ID }, new int[] {
R.id.name, R.id.address, R.id.businessId});
businessListObj.setAdapter(adapter);
businessListObj.setClickable(true);
businessListObj.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
{
Intent detailsIntent = new Intent(HomeActivity.this, DetailActivity.class);
startActivity(detailsIntent);
}
});
我努力了
Object o = businessListObj.getAdapter().getItem(position);
但我似乎无法弄清楚从对象中获取名称、地址和 ID 以传递给下一个活动的语法。
编辑:XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/businessId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
编辑 2:商业清单:
ArrayList<HashMap<String, String>> businessList = new ArrayList<HashMap<String, String>>();