我有一个ListView
通过从 mysql db 获取数据来填充的......它ListView
包含来自数据库的三个值......
- 姓名
- 类别
- 位置
我想将这些值传递给下一个Activity
。所以我用
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String items = parent.getItemAtPosition(position).toString();
Intent intent = new Intent();
intent.setClass(mapping, CheckIn.class);
intent.putExtra("name", items);
startActivity(intent);
}
});
但它会产生一个数组 {name = xxx , category = asdasd , position = ddxxddxx}
在第二个Activity
中,我想获取有关该指定名称的用户评论并将其插入到另一个表中。如何使用数组这样做?
完整代码
try {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(params, 0);
HttpClient httpClient = new DefaultHttpClient(params);
// prepare the HTTP GET call
HttpGet httpget = new HttpGet("http://hopscriber.com/place.php");
// get the response entity
HttpEntity entity = httpClient.execute(httpget).getEntity();
if (entity != null) {
// get the response content as a string
String response = EntityUtils.toString(entity);
// consume the entity
entity.consumeContent();
// When HttpClient instance is no longer needed, shut down the
// connection manager to ensure immediate deallocation of all
// system resources
httpClient.getConnectionManager().shutdown();
// return the JSON response
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
JSONArray jsonArray = new JSONArray(response);
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = (JSONObject) jsonArray.get(i);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_Name, object.getString("name"));
map.put(TAG_Category, object.getString("category"));
contactList.add(map);
}
}
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.menu_list_row, new String[] { TAG_Name,
TAG_Category }, new int[] { R.id.LR_Name,
R.id.LR_date });
list.setAdapter(adapter);
}
} catch (Exception e) {
e.printStackTrace();
}
// Launching new screen on Selecting Single ListItem
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String items = parent.getItemAtPosition(position).toString();
Intent intent = new Intent();
intent.setClass(mapping, CheckIn.class);
intent.putExtra("name", items);
startActivity(intent);
}
});
}