Я работаю над recyclerview и картой, чтобы загрузить некоторые изображения с помощью библиотеки Picasso. Я вставляю свой код здесь.Я не могу отображать изображения с помощью Picasso ImageLoader
Это мой DivineDestinationDistricWiseActivity.
public class DivineDestinationsDistrictWise extends Fragment {
RecyclerView all_divine_dest_places_list;
List<Places> placesList;
GridLayoutManager glm;
public DivineDestinationsDistrictWise() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_divine_destinations_district_wise, container, false);
all_divine_dest_places_list = (RecyclerView) rootView.findViewById(R.id.all_divine_places_rv_id);
glm = new GridLayoutManager(getActivity() , 2);
all_divine_dest_places_list.setLayoutManager(glm);
all_divine_dest_places_list.setHasFixedSize(true);
intializeData();
initializeAdapter();
return rootView;
}
private void intializeData() {
placesList = new ArrayList<>();
placesList.add(new Places("Divine Destinations", R.drawable.hyd_balakampeta_ellamma));
placesList.add(new Places("Adventure Journeys", R.drawable.hyd_birla_mandir));
placesList.add(new Places("boatings", R.drawable.hyd_jagannatha_temple));
placesList.add(new Places("Heritage Spots", R.drawable.hyd_mecca_masjid));
placesList.add(new Places("Shopping", R.drawable.hyd_peddamma_temple));
placesList.add(new Places("Nature Discovery", R.drawable.hyd_peddamma_temple));
placesList.add(new Places("Wild Life", R.drawable.wild_life_main));
}
private void initializeAdapter()
{
DDDWAdapter adapter =new DDDWAdapter(placesList);
// places_type_list_recyclerView.addItemDecoration(new SimpleDividerItemDecoration(this));
all_divine_dest_places_list.setAdapter(adapter);
}
}
Это мой адаптер класса.
public class DDDWAdapter extends RecyclerView.Adapter<DDDWAdapter.DivineDestViewHolder> {
CardView cv;
Context context;
public class DivineDestViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
TextView personName;
ImageView photo_city;
public DivineDestViewHolder(View itemView) {
super(itemView);
cv=(CardView)itemView.findViewById(R.id.cardview_places_id);
personName=(TextView)itemView.findViewById(R.id.places_list_id_tv);
photo_city=(ImageView)itemView.findViewById(R.id.image_places_list_id);
context = itemView.getContext();
photo_city.setOnClickListener(this);
}
@Override
public void onClick(View v) {
}
}
List<Places> place;
DDDWAdapter(List<Places> place)
{
this.place=place;
}
@Override
public DivineDestViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.places_type_list, parent, false);
DivineDestViewHolder pvh = new DivineDestViewHolder(v);
return pvh;
}
@Override
public void onBindViewHolder(DivineDestViewHolder holder, int position) {
holder.personName.setText(place.get(position).city_name);
holder.photo_city.setImageResource(place.get(position).photo);
//here i am trying to load images with Picasso Library but not getting Images.
Picasso.with(context).load(R.id.image_places_list_id).into(holder.photo_city);
}
@Override
public int getItemCount() {
return place.size();
}
}
Это мой класс мест.
public class Places {
String city_name;
int photo;
Places(String city_name, int photo)
{
this.city_name = city_name;
this.photo=photo;
}
}
Я попытался вставить, как показано ниже, если я использую это, я получаю изображения. Но когда я просматриваю экран, изображения прокручиваются с небольшим рывком.
Picasso.with(context).load(place.get(position).photo).into(holder.photo_city);
Пожалуйста, помогите мне с этим ... Спасибо заранее .....
изображение находится в вашей папке ресурсов, так что размер вашего apk большой, поэтому андроид не выделяет память для вашего приложения. Проблема gn пришла попытаться получить от сети, как URL –
@Naveen Спасибо за ваш ответ .. Нет ли альтернативного способа сделать ... без получения его из сетевого URL. –