我有从服务器下载的图像,当我点击在另一个活动中打开的图像时,我将其下载到网格视图中我需要在打开第二个活动时在图像之间切换我的代码中出错了什么?
public class customswitcher extends PagerAdapter{
Context c;
ArrayList<photos> sites;
LayoutInflater inflater;
public customswitcher(Context c, ArrayList<photos> sites)
{
this.c = c;
this.sites = sites;
}
@Override
public int getCount() {
return 0;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view== (LinearLayout) object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.imageswitcher,container,false);
ImageView imageView = (ImageView) view.findViewById(R.id.iv);
photos photos = sites.get(position);
Picasso.with(c).load(photos.getImage()).into(imageView);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}
}
public class Funny extends AppCompatActivity {
MyDataBase dataBase = new MyDataBase(Funny.this);
String url = "http://javawy.fulba.com/yphotos.php";
ProgressDialog dialog;
String pw;
List<photos> list;
photos posts;
customfunny adapter;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_funny);
list= dataBase.getallcontacts();
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);
pw = object1.getString("image");
posts = new photos(pw);
dataBase.AddnewContact(posts);
list.add(posts);
}
dialog.dismiss();
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
dialog.dismiss();
Toast.makeText(Funny.this,"اتصل بالانترنت لتحصل علي احيث الصور",Toast.LENGTH_LONG).show();
}
});
adapter = new customfunny(Funny.this,list);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
photos photos = (com.example.yasser.ahlysc.photos) gridView.getItemAtPosition(i);
Intent intent = new Intent(Funny.this,SelectedImage.class);
intent.putExtra("one",photos.getImage());
startActivity(intent);
adapter.notifyDataSetChanged();
}
});
dialog = new ProgressDialog(Funny.this);
dialog.setTitle("downloading");
dialog.setMessage("جاري تحديث الصور....انتظر");
dialog.show();
Volley.newRequestQueue(Funny.this).add(stringRequest);
}
}
public class SelectedImage extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selected_image);
Intent i = getIntent();
String s = i.getStringExtra("one");
ArrayList<photos> list = new ArrayList<>();
list.add(new photos(s));
ViewPager pager = (ViewPager) findViewById(R.id.vp);
customswitcher customswitcher = new customswitcher(SelectedImage.this,list);
pager.setAdapter(customswitcher);
}
}