【发布时间】:2016-01-18 13:29:00
【问题描述】:
我有一个使用 ArrayAdapter 创建的 ListView,它使用 JSON 解析从 MySQL 数据库获取不同的值。现在,当用户单击列表中的项目时,我将其中一些值传递给下一个活动:
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id)
{
Intent intent = new Intent(ListActivity.this, ListingDescription.class);
String place_name = ((TextView) v.findViewById(R.id.textView3)).getText().toString();
intent.putExtra("place_name",place_name);
startActivity(intent);
这很好,但现在我想从 MySQL 数据库中获取另外 2 个不应该显示在 ListView 中的值。我应该走哪条路? 我尝试在 ArrayAdapter 中添加值,但后来我意识到我正在通过获取 textview 信息来传递值。如何在不显示在 ListView 中的情况下从 ArrayList 适配器传递一些信息? 也许有其他方法可以做到这一点?
这就是我解析 JSON 的方式:
for (int i=0; i<theJson.length(); i++){
Places place = new Places();
JSONObject jRealObject = theJson.getJSONObject(i);
place.setImage(jRealObject.getString("image"));
place.setName(jRealObject.getString("name"));
place.setLocation_address(jRealObject.getString("location_address"));
place.setOpen_until(jRealObject.getString("open_until"));
placeslist.add(place);
我也考虑过在布局中将值设置为不可见,但我认为这绝对不是要走的路。如有任何帮助,我将不胜感激!
【问题讨论】:
标签: android mysql json listview android-listview