I have a listView that has information inside, and when I click on one row, it should provide me with all the details under this selected row, in this selection row I have an image, image, price, etc. therefore, when I click on an image in a listView, it should fill in all the information, including the image, in the next step.
I tried to display a View in my list, and that’s fine, here is my code:
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);
i.putExtra("product", selectedValue);
startActivity(i);
}
}
EDIT:
private final Context context;
private final String[] myBookNamelist = null;
private ArrayList<String> MyP = new ArrayList<String>();
private ArrayList<String> myPurl = new ArrayList<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;
JSONObject json = JSONfunctions.getJSONfromURL("http://10.0.2.2/php/p.php");
try{
JSONArray earthquakes = json.getJSONArray("prop");
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) {
err.printStackTrace();
} catch (IOException err) {
err.printStackTrace();
}
imageView.setImageBitmap(bitmap);
System.out.println("Bitmap image: "+position+"="+bitmap);
return rowView;
}
}
And I can pass the position to the next class, but how to get all the information from the selected row?