۱۳۹۶/۰۲/۲۵, ۰۷:۲۲ ب.ظ
سلام دوستان خسته نباشید
من یک پروژه دارم کتابخانه Volley میخواستم با اسکرول اطلاعات مثلا ۳ تا ۳ تا لود بشه و همینطور تا اخر. ممنون میشم یکی قدم به قدم بهم بگه. اولین تج
این adapeter:
اینم اکتیویتی که نمایش میدم اطلاعات:
من یک پروژه دارم کتابخانه Volley میخواستم با اسکرول اطلاعات مثلا ۳ تا ۳ تا لود بشه و همینطور تا اخر. ممنون میشم یکی قدم به قدم بهم بگه. اولین تج
این adapeter:
کد:
public class PlaceAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Place> placeList;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public PlaceAdapter(Activity activity, List<Place> placeList) {
this.activity = activity;
this.placeList = placeList;
}
@Override
public int getCount() {
return placeList.size();
}
@Override
public Object getItem(int location) {
return placeList.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.single_place_row, null);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
NetworkImageView place_image = (NetworkImageView) convertView
.findViewById(R.id.img_place);
place_image.setScaleType(NetworkImageView.ScaleType.FIT_XY);
TextView place_title = (TextView) convertView.findViewById(R.id.txt_place_name);
TextView place_intro = (TextView) convertView.findViewById(R.id.txt_place_intro);
TextView place_cat = (TextView) convertView.findViewById(R.id.txt_place_cat);
// getting place data for the row
Place m = placeList.get(position);
place_image.setImageUrl(m.getImage() , imageLoader);
place_title.setText(m.getName());
place_intro.setText(m.getIntro());
place_cat.setText(m.getCat());
return convertView;
}
}
اینم اکتیویتی که نمایش میدم اطلاعات:
کد:
public class All_pois_Fragment extends Fragment {
private String Request_URL = "555555555555555555555555555555555555555555222222222222";
private ProgressDialog pDialog;
private List<Place> placeList = new ArrayList<Place>();
private ListView list_show_all;
private PlaceAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab1.xml
View view = inflater.inflate(R.layout.fragment_all_pois, container, false);
list_show_all = (ListView) view.findViewById(R.id.list_all_pois);
adapter = new PlaceAdapter(getActivity(), placeList);
list_show_all.setAdapter(adapter);
pDialog = new ProgressDialog(getContext());
// Showing progress dialog before making http request
pDialog.setMessage("در حال ارتباط با سرور...");
pDialog.show();
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, Request_URL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
hidePDialog();
try {
JSONArray array = response.getJSONArray("places");
for (int i = 0; i < array.length() ; i++) {
JSONObject temp = array.getJSONObject(i);
Place place = new Place();
place.setName(temp.getString("name"));
place.setIntro(temp.getString("intro"));
place.setImage(temp.getString("image"));
place.setCat(temp.getString("cat"));
placeList.add(place);
/*Toast.makeText(PlaceActivity.this, temp.toString(), Toast.LENGTH_LONG).show();*/
}
} catch (JSONException e) {
Toast.makeText(getActivity(),"خطا در کش" + e.toString(), Toast.LENGTH_LONG).show();
}
adapter.notifyDataSetChanged();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(),"خطا در رسپونس"+ error.toString(), Toast.LENGTH_LONG).show();
}
}
);
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
return view;
}
@Override
public void onDestroy() {
super.onDestroy();
hidePDialog();
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
}