我从json服务器下载图像视图中的图像我需要在单击时打开图像并将图像的位置发送到包含图像视图的活动以接收已发送的照片但我的问题是imageView.setImageResource (list.get(ReceivedPosition))从这里的自定义对象照片中获取一个intger和我的照片列表
public class customfunny extends BaseAdapter {
Context c;
ArrayList<photos> sites;
public customfunny(Context c, ArrayList<photos> sites)
{
this.c = c;
this.sites = sites;
}
@Override
public int getCount() {
return sites.size();
}
@Override
public Object getItem(int i) {
return sites.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view==null)
{
view = LayoutInflater.from(c).inflate(R.layout.funnyinflate,viewGroup,false);
}
ImageView imageView = (ImageView) view.findViewById(R.id.imageView1);
photos site = (photos) this.getItem(i);
Picasso.with(c).load(site.getImage()).into(imageView);
return view;
}
}
pulbic class Funny extends AppCompactActivity{String url = "http://javawy.fulba.com/yphotos.php";
ProgressDialog dialog;
ArrayList<photos> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_funny);
final GridView gridView = (GridView) findViewById(R.id.gridview);
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject object = new JSONObject(response);
JSONArray jsonArray = object.getJSONArray("photos");
list = new ArrayList<>();
for (int i = 0;i<jsonArray.length();i++)
{
JSONObject object1 = jsonArray.getJSONObject(i);
String pw = object1.getString("image");
photos posts = new photos(pw);
list.add(posts);
}
customfunny adapter = new customfunny(Funny.this,list);
gridView.setAdapter(adapter);
dialog.dismiss();
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
dialog.dismiss();
Toast.makeText(Funny.this,"error",Toast.LENGTH_LONG).show();
}
});
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(Funny.this,SelectedImage.class);
intent.putExtra("one",i);
}
});
dialog = new ProgressDialog(Funny.this);
dialog.setTitle("downloading");
dialog.setMessage("wait......");
dialog.show();
Volley.newRequestQueue(Funny.this).add(stringRequest);
}}
public class SelectedImage extends AppCompactActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selected_image);
Intent i = getIntent();
int position = i.getExtras().getInt("one");
ImageView imageView = (ImageView) findViewById(R.id.result);
imageView.setImageResource(new Funny().list.get(position));//compiler error
}}
答案 0 :(得分:0)
只需将实际网址传递到意图中,然后使用Picasa将图片下载到视图中。 Picasa内部已经缓存了图片。您没有理由重新创建Funny Class和Adapter。