我正在GridView
中显示来自网络服务的图片。当用户选择GridView
中的项目时,它会打开ViewsFlipper以更大的分辨率显示相同的图像(从具有其他链接的Web服务获取)
问题是当用户在GridView
中选择第3项时,它会打开带有Ist项目的ViewFlipper(不包含第3项)
如何传递所选项目的位置?
GridViewActivity.java
grid_view.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
TextView txt_product_name=(TextView)view.findViewById(R.id.txt_prod_name);
String product_name=txt_product_name.getText().toString();
TextView txt_product_path=(TextView)view.findViewById(R.id.txt_prod_fetch_name);
String product_path=txt_product_path.getText().toString();
TextView txt_product_id=(TextView)view.findViewById(R.id.txt_prod_id);
String product_id=txt_product_id.getText().toString();
TextView txt_product_details=(TextView)view.findViewById(R.id.txt_prod_details);
String product_details=txt_product_details.getText().toString();
Intent intent=new Intent(GetInspiredProducts.this,ViewFlipperActivity.class);
intent.putExtra("product_name", product_name);
intent.putExtra("product_path", product_path);
intent.putExtra("product_id", product_id);
intent.putExtra("product_details", product_details);
intent.putExtra("cat_id", cat_id);
startActivity(intent);
}
});
ViewFlipperActivity.java
protected List doInBackground(String... params) {
// TODO Auto-generated method stub
if (NetworkCheck.isNetworkAvailable(GetInspiredProductDetail.this)==true) {
try{
jsonObj=userFunctions.getInspiredProducts(cat_id);
Log.e("getInspiredCategory", "kargetinsp "+jsonObj);
JSONArray json_array=jsonObj.getJSONArray("posts");
for (int i = 0; i < json_array.length(); i++)
{
JSONObject json_obj=json_array.getJSONObject(i);
String category=json_obj.getString("post");
JSONObject json_obj_=new JSONObject(category);
String picture_path=json_obj_.getString("PicturePath");
String picture_name=json_obj_.getString("PictureName");
String picture_id=json_obj_.getString("PictureId");
String picture_details=json_obj_.getString("PictureDetails");
HashMap<String, String> hash_map=new HashMap<String, String>();
hash_map.put("flipper_image",AllLinks.PRODUCTS_LARGE_IMAGE_URI+picture_path);
hash_map.put("flipper_name",picture_name);
hash_map.put("flipper_path",picture_path);
category_hash_map.add(hash_map);
Log.e("VIEW_FLIPPER1", "karjeev "+picture_path);
/*HashMap<String, String> hash_map=new HashMap<String, String>();
hash_map.put("products_pic_path", AllLinks.PRODUCTS_THUMB_PICTURE_PATH+picture_path);
hash_map.put("products_pic_name", picture_name);
category_hash_map.add(hash_map); */
}
}
catch (Exception e) {
e.printStackTrace();
}
}
ViewFlipperAdapter.java
public Object instantiateItem(View container, int position) {
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
View view = mInflater.inflate(R.layout.demo_page_copy, null);
((ViewPager) container).addView(view, 0);
ImageView img = (ImageView) view.findViewById(R.id.list_image);
TextView txtName = (TextView) view.findViewById(R.id.txt_prod_det);
final TextView txtPath = (TextView) view.findViewById(R.id.txt_prod_path);
imageLoader.DisplayImage(song.get("flipper_image"),img);
txtName.setText(song.get("flipper_name"));
txtPath.setText(song.get("flipper_path"));
view.setContentDescription(content);
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String path=txtPath.getText().toString();
Log.d("image path", String.valueOf(v.getContentDescription()));
Intent intent=new Intent(context,ImageZoom.class);
intent.putExtra("image", AllLinks.PRODUCTS_LARGE_IMAGE_URI+path);
context.startActivity(intent);
}
});
return view;
}