我有一个 listView 里面有信息,当我单击一行时,它必须在该选定行下给我所有详细信息,在该选择行中我有图像、图像名称、价格等,所以当我单击 listView 中的图像时,它必须填充所有信息,包括下一个活动的图像
我试图在我的 listView 上显示,没关系,这是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
JSONObject json = JSONfunctions.getJSONfromURL("http://10.0.2.2/php/p.php");
try{
JSONArray earthquakes = json.getJSONArray("prop");
for(int i=0;i<earthquakes.length();i++){
JSONObject e = earthquakes.getJSONObject(i);
String BookName = e.getString("P_City");
PNames.add(BookName);
String BookImg = e.getString("Pname");
PImages.add(BookImg);
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
setListAdapter(new MobileArrayAdapter(this, PNames,PImages));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String selectedValue = (String) getListAdapter().getItem(position);
Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), Searching.class);
// sending data to new activity
i.putExtra("product", selectedValue);
startActivity(i);
}
}
编辑 :
private final Context context;
private final String[] myBookNamelist = null;
private ArrayList<String> MyP = new ArrayList<String>();
private ArrayList<String> myPurl = new ArrayList<String>();
//ArrayList<HashMap<String, String>> myBookNamelist = new ArrayList<HashMap<String, String>>();
//ArrayList<HashMap<String, String>> myBookImageurl = new ArrayList<HashMap<String, String>>();
public MobileArrayAdapter(Context context,ArrayList<String> Bname,ArrayList<String> BUrl) {
super(context, R.layout.list_mobile, Bname);
this.context = context;
this.MyP = Bname;
this.myPurl = BUrl;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_mobile, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(MyP.get(position));
Bitmap bitmap = null;
// Change icon based on name
JSONObject json = JSONfunctions.getJSONfromURL("http://10.0.2.2/php/p.php");
// http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo
try{
JSONArray earthquakes = json.getJSONArray("prop");
//for(position=0;position<earthquakes.length();position++){
JSONObject e = earthquakes.getJSONObject(position);
String BB = e.getString("P_City");
MyP.add(BB);
String UU = e.getString("Pname");
myPurl.add(UU);
//}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
String s = MyP.get(position);
String i = myPurl.get(position);
System.out.println(s);
System.out.println(i);
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(i).getContent());
} catch (MalformedURLException err) {
// TODO Auto-generated catch block
err.printStackTrace();
} catch (IOException err) {
// TODO Auto-generated catch block
err.printStackTrace();
}
//if (!s.equals("")) {
imageView.setImageBitmap(bitmap);
//} else {
System.out.println("Bitmap image: "+position+"="+bitmap);
//imageView.setImageResource(R.drawable.android_logo);
//}
return rowView;
}
}
我可以将位置传递给下一堂课,但是如何从选定的行中获取所有信息?