FolderListAdapter Code
public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.myViewHolder> {
private final Context context;
private final ArrayList<Folder> folderList;
public FolderListAdapter(Context context, ArrayList<Folder> folderList) {
this.context = context;
this.folderList = folderList;
}
#NonNull
#Override
public myViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.folder_view, parent, false);
return new myViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull myViewHolder holder, int position) {
Folder folder = folderList.get(position);
Glide.with(context).load(folder.getFolder()).into(holder.imageView);
holder.folder_name.setText(folder.getFolder().getName());
holder.folder_item_count.setText(folder.getFilesList().size() + " Items");
}
#Override
public int getItemCount() {
return folderList.size();
}
public class myViewHolder extends RecyclerView.ViewHolder {
private final ShapeableImageView imageView;
private final TextView folder_name;
private final TextView folder_item_count;
public myViewHolder(#NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.folder_image_view);
folder_name = itemView.findViewById(R.id.folder_name_text_view);
folder_item_count = itemView.findViewById(R.id.folder_items_count_text_view);
}
}
}
MainActivity Code for RecyclerView
FolderListAdapter adapter = new FolderListAdapter(this, folderList);
RecyclerView recyclerView = binding.folderRecyclerView;
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
XML CODE OF recycler view
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/folder_recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="#layout/folder_view" />
folder_view.xml code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/folder_image_view"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="?android:attr/selectableItemBackground"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay.App.CornerSize50Percent"
tools:srcCompat="#tools:sample/backgrounds/scenic" />
<TextView
android:id="#+id/folder_name_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="Camera"
android:textColor="#android:color/primary_text_light"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="#+id/folder_image_view"
app:layout_constraintStart_toStartOf="#+id/folder_image_view"
app:layout_constraintTop_toBottomOf="#+id/folder_image_view" />
<TextView
android:id="#+id/folder_items_count_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="600 Items"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="#+id/folder_name_text_view"
app:layout_constraintTop_toBottomOf="#+id/folder_name_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_folder.xml layout file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.addFiles.FoldersActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/folder_recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT
The size of folderList is 2
I also check the size of adapter. It is also 2
I also tried by making a new Adapter but it also does not work.
I don't know where I am making mistake and why it is now showing nothing in activity.
Change 1 :
In the xml set attribute android:layout_width="0dp" to android:layout_width="match_parent" and android:layout_height="0dp" to android:layout_height="match_parent"
Change 2 :
In your MainActivity code set LayoutManager to the RecyclerView before setting up adapter. so the code goes this way :
//Defining RecyclerView and setting LayoutManager
RecyclerView recyclerView = binding.folderRecyclerView;
FolderListAdapter adapter = new FolderListAdapter(this, folderList);
//Setting up Adapter
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.setAdapter(adapter);
Related
I am working on food delivery application. I have four tab in menu bar Home, Daily Meal, Favourite and My Cart. My all tab is work well but when I click on Daily Meal my page is rendering. What can I try next?
Here is my code:
daily_meal_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.DailyMeal.DailyMealFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/daily_meal_rec"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
daily_meal_ver.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<ImageView
android:id="#+id/imgview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/breakfast"
android:foreground="#drawable/blur"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/amita_bold"
android:text="Dinner"
android:textColor="#color/white"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/imgview"
app:layout_constraintEnd_toEndOf="#+id/imgview"
app:layout_constraintStart_toStartOf="#+id/imgview"
app:layout_constraintTop_toTopOf="#+id/imgview"
app:layout_constraintVertical_bias="0.3" />
<TextView
android:id="#+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/amita"
android:text="Choose your best dinner"
android:textColor="#color/white"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/names" />
<TextView
android:id="#+id/discounts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/off_back"
android:padding="2sp"
android:text=" 20% OFF "
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/imgview"
app:layout_constraintStart_toStartOf="#+id/imgview"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.821" />
</androidx.constraintlayout.widget.ConstraintLayout>
DailyMealModel.java
public class DailyMealModel {
int image;
String name;
String discount;
String description;
// getter setter and constructor
}
DailyMealFragment.java
public class DailyMealFragment extends Fragment {
RecyclerView recyclerView;
List<DailyMealModel> dailyMealModels;
DailyMealAdapter dailyMealAdapter;
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.daily_meal_fragment,container,false);
recyclerView = root.findViewById(R.id.daily_meal_rec);
dailyMealModels = new ArrayList<>();
dailyMealModels.add(new DailyMealModel(R.drawable.breakfast,"Breakfast","30% OFF","Description Description"));
dailyMealModels.add(new DailyMealModel(R.drawable.lunch,"Lunch","15% OFF","Description Description"));
dailyMealAdapter = new DailyMealAdapter(getContext(),dailyMealModels);
recyclerView.setAdapter(dailyMealAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
return root;
}
}
DailyMealAdapter.java
public class DailyMealAdapter extends RecyclerView.Adapter<DailyMealAdapter.viewholder> {
Context context;
List<DailyMealModel> list;
public DailyMealAdapter(Context context, List<DailyMealModel> list) {
this.context = context;
this.list = list;
}
#NonNull
#Override
public viewholder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return new viewholder(LayoutInflater.from(parent.getContext()).inflate(R.layout.daily_meal_ver,parent,false));
}
#Override
public void onBindViewHolder(#NonNull viewholder holder, int position) {
holder.img.setImageResource(list.get(position).getImage());
holder.name.setText(list.get(position).getName());
holder.discount.setText(list.get(position).getDiscount());
holder.description.setText(list.get(position).getDescription());
}
#Override
public int getItemCount() {
return list.size();
}
public class viewholder extends RecyclerView.ViewHolder {
ImageView img;
TextView name,discount,description;
public viewholder(#NonNull View itemView) {
super(itemView);
img = itemView.findViewById(R.id.imgview);
name = itemView.findViewById(R.id.names);
description = itemView.findViewById(R.id.desc);
discount = itemView.findViewById(R.id.discounts);
}
}
}
Snapshot
As your attached screenshot,
please make sure all images and icons used in the app are lower sizes even loading dynamic images for that you can use tinypng.com or tinyjpg.com
also, using pagination in RecyclerView will improve your app performance.
and make sure JSON/XML list response is minimal.
I tried a lot of solutions but no solution has worked for me.
I am getting data from the server and showing it inside a recycleview. The data shows fine but shows this error in the logcat
Access denied finding property "persist.vendor.log.tel_dbg"
E/RecyclerView: No adapter attached; skipping layout
E/RecyclerView: No adapter attached; skipping layout
sometimes when I refresh again and again the recyclerview becomes empty.
I am using viewpager consisting of 2 fragments inside a parent fragment.
this recycleview is using in a nested scrollview
some time data not showing
Code snippet:
homebuyer_adapter_recycler=new homebuyer_adapter_recycle(getActivity(), items);
LinearLayoutManager home = new LinearLayoutManager(getActivity());
home.setOrientation(LinearLayoutManager.VERTICAL);
allitemsgrid.setLayoutManager(home);
allitemsgrid.setAdapter(r);
Here is more about
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent,
final int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.items_view,parent,
false);
RecyclerView.LayoutParams lp = new
RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
v.setLayoutParams(lp);
ViewHolder viewHolder = new ViewHolder(v);
HERE IS MY item view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
app:cardCornerRadius="6dp"
android:layout_marginBottom="3dp"
app:cardBackgroundColor="#color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp">
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="match_parent"
android:layout_height="150dp"
app:riv_corner_radius="6dp"
android:id="#+id/image_items"
android:scaleType="fitXY"
/>
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="match_parent"
android:layout_height="150dp"
app:riv_corner_radius="6dp"
android:background="#drawable/blackshade"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/items_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/_5sdp"
android:textColor="#color/white"
android:fontFamily="sans-serif-smallcaps"
android:paddingLeft="20dp"
android:text="Message" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:text="Timing"
android:padding="#dimen/_5sdp"
android:textColor="#color/white"
android:layout_alignParentBottom="true"
android:fontFamily="#font/mylight"
android:layout_alignParentRight="true"
android:textSize="10dp"
android:id="#+id/shoptimming"/>
</RelativeLayout>
<TextView
android:id="#+id/name_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:alpha="0.6"
android:fontFamily="#font/arimo_bold"
android:paddingLeft="20dp"
android:text="Name"
android:textColor="#color/black"
android:textSize="17dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:orientation="horizontal">
<TextView
android:id="#+id/minumum_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:drawablePadding="10dp"
android:fontFamily="sans-serif"
android:paddingLeft="20dp"
android:text="Minimum " />
<TextView
android:id="#+id/price_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif"
android:gravity="left"
android:paddingLeft="20dp"
android:text="charges"
/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Here is my adapter class
public class homebuyer_adapter_recycle extends RecyclerView.Adapter<homebuyer_adapter_recycle.ViewHolder> {
private ArrayList<seller_information> listData;
private LayoutInflater layoutInflater;
int lastpostition=-1;
Context context;
public homebuyer_adapter_recycle(Context aContext, ArrayList<seller_information> listData) {
this.listData = listData;
layoutInflater = LayoutInflater.from(aContext);
context=aContext;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder
(#NonNull ViewGroup parent, final
int viewType) {
View v = LayoutInflater.from(parent.getContext()).
inflate(R.layout.items_view,parent, false);
ViewHolder viewHolder = new ViewHolder(v);
Log.i("inadapter","calling time");
v.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
phone_number_shop = listData.get(viewType).getPhonenumber();
homebuyer.Delivery_charges_shop =
listData.get(viewType).getDiliveryfee();
homebuyer.Shop_name = listData.get(viewType).getShopname();
homebuyer.minimum_order = listData.get(viewType).getMinorder();
//profession=items.get(i).getName();
// Toast.makeText(getActivity(),phn,Toast.LENGTH_SHORT).show();
all_and_cetegory_items items = new all_and_cetegory_items();
Bundle b = new Bundle();
b.putString("phone",homebuyer.phone_number_shop);
items.setArguments(b);
FragmentTransaction fragmentTransaction =
((AppCompatActivity)context).getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.replace(R.id.nav_host_fragment, items);
fragmentTransaction.addToBackStack(null).commit();
}
});
return viewHolder;
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.name.setText(listData.get(position).getShopname());
//
Picasso.with(context).load(listData.get(position)
.getShopimage()).into(holder.shopimage);
Glide.with(context).load(listData.get(position).getShopimage())
.into(holder.shopimage);
holder.dilivery.setText("Rs "+listData.get(position).getDiliveryfee()+"
Delivery fee");
holder.minorder.setText("Rs "+listData.get(position).getMinorder()+" minimum");
holder.items.setText(listData.get(position).getShopmessage());
holder.time.setText("Service Available
"+listData.get(position).getStartingtime()+" to
"+listData.get(position).getEndingtime());
Log.i("inadapter","calling time"+listData.get(position).getShopname());
}
#Override
public int getItemCount() {
return listData.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name;
TextView dilivery;
TextView items;
TextView minorder;
TextView time;
ImageView shopimage;
public ViewHolder(#NonNull View v) {
super(v);
name = (TextView) v.findViewById(R.id.name_item);
dilivery = (TextView) v.findViewById(R.id.price_item);
minorder = (TextView) v.findViewById(R.id.minumum_order);
items=(TextView)v.findViewById(R.id.items_all);
time=(TextView)v.findViewById(R.id.shoptimming);
shopimage=(ImageView) v.findViewById(R.id.image_items);
}
}
}
In error it is saying that the Adapter for RecylerView is not attached. So, try to add adapter to the layout using:
recyclerView.setAdapter(categoryAdapter);
I am assuming homebuyer_adapter_recycler is your adapter.
According to that, you haven't really set your adapter as the logcat is specifying.
Add the below code instead of allitemsgrid.setAdapter(r);
allitemsgrid.setAdapter(homebuyer_adapter_recycler);
If my assumption or suggestion is wrong, it is okay. It is probably because your question is not very clear and does not provide the necessary details. Please provide more details such as the adapter class code and what is allitemsgrid, homebuyer_adapter_recycler and r.
Before marking as duplicate et al, viewpager from recyclerview is kind of triccky. The code is able to retrieve data from db and display it in a recyclerview with cardview. I want to be able to scroll the images in the viewpager while in the recyclerview as shown in the wireframe below, the dots represent number of images retrieved from DB which should be swipeeable right or left. Imageview seems not to be swipeable.
IMAGE ADAPTER.JAVA
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
List<ImageList>imageLists;
Context context;
public ImageAdapter(List<ImageList> imageLists, Context context) {
this.imageLists = imageLists;
this.context = context;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.image_list,parent,false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
ImageList imageList = imageLists.get(position);
holder.tvname.setText(imageList.getName());
holder.tv2name.setText(imageList.getName2());
String picture = imageList.getImageurl();
String picture2 = imageList.getImage2url();
String picture3 = imageList.getImage3url();
String[] imageUrls = {picture, picture2, picture3};
Picasso.get()
.load(picture)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resize(0, 200)
.into(holder.img);
}
#Override
public int getItemCount() {
return imageLists.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView tvname, tv2name;
private ImageView img;
public ViewHolder(View itemView) {
super(itemView);
img=(ImageView)itemView.findViewById(R.id.image_view);
tvname=(TextView)itemView.findViewById(R.id.txt_name);
tvname=(TextView)itemView.findViewById(R.id.txt_name2);
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:cardElevation="3dp"
app:cardUseCompatPadding="true"
android:padding="2dp"
android:layout_margin="5dp">
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="ServerImg"
android:scaleType="fitXY" />
</androidx.cardview.widget.CardView>
<TextView
android:textSize="25sp"
android:textColor="#color/colorPrimaryDark"
android:textStyle="bold"
android:id="#+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:textSize="25sp"
android:textColor="#color/colorPrimaryDark"
android:textStyle="bold"
android:id="#+id/txt_name2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
I am trying to make a movie list, but it only shows a white screen with the app name. Apparently, I have a very similar program to this and it runs perfectly fine. This is what I get when I run the program.
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
I found someone saying that this error happens if there is an error in xml codes, but I will still put my java codes as well.
public class MainActivity extends AppCompatActivity {
private ListView mListView;
private Context mContext;
ArrayList<Movie> movieList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
final ArrayList<Movie> movieList = Movie.getMoviesFromFile("movies.json", this);
MovieAdapter adapter = new MovieAdapter(this, movieList);
mListView = findViewById(R.id.movie_list_view);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Movie selectedMovie = movieList.get(i);
Intent detailIntent = new Intent(mContext, MovieDetailActivity.class);
detailIntent.putExtra("title", selectedMovie.title);
detailIntent.putExtra("description", selectedMovie.description);
detailIntent.putExtra("poster", selectedMovie.poster);
startActivity(detailIntent);
}
});
}
The following is my adapter.
public class MovieAdapter extends BaseAdapter{
private Context mContext;
private ArrayList<Movie> mMovieList;
private LayoutInflater mInflater;
public MovieAdapter(Context mContext, ArrayList<Movie> mMovieList){
this.mContext = mContext;
this.mMovieList = mMovieList;
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount(){return mMovieList.size();}
#Override
public Object getItem(int pos){return mMovieList.get(pos);}
#Override
public long getItemId(int pos){return pos;}
#Override
public View getView(int pos, View convertView, ViewGroup parent){
ViewHolder holder;
if(convertView == null){
convertView = mInflater.inflate(R.layout.list_item_movie, parent, false);
holder = new ViewHolder();
holder.titleTextView = convertView.findViewById(R.id.title);
holder.charactersTextView = convertView.findViewById(R.id.main_characters);
holder.descriptionTextView = convertView.findViewById(R.id.description);
holder.thumbnailImageView = convertView.findViewById(R.id.poster);
convertView.setTag(holder);
} else{
holder = (ViewHolder)convertView.getTag();
}
TextView titleTextView = holder.titleTextView;
TextView descriptionTextView = holder.descriptionTextView;
TextView charactersTextView = holder.charactersTextView;
ImageView thumbnailImageView = holder.thumbnailImageView;
Movie movie = (Movie)getItem(pos);
titleTextView.setText(movie.title);
titleTextView.setTextSize(20);
charactersTextView.setText(movie.main_characters);
charactersTextView.setTextSize(13);
descriptionTextView.setText(movie.description);
descriptionTextView.setTextSize(9);
Picasso.with(mContext).load(movie.poster).into(thumbnailImageView);
return convertView;
}
private static class ViewHolder{
public TextView titleTextView;
public TextView descriptionTextView;
public ImageView thumbnailImageView;
public TextView charactersTextView;
}
}
And the followings are the xml codes.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.junepyolee_miniapp1.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/movie_list_view" />
list_item_movie.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/poster"
android:layout_width="90dp"
android:layout_height="140dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="4dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_centerVertical="true"
android:scaleType="fitCenter"
android:contentDescription="This is a thumbnail"
app:srcCompat="#mipmap/ic_launcher" />
<RelativeLayout
android:id="#+id/movie_list_text_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/poster"
android:layout_alignParentTop="false"
android:layout_toRightOf="#+id/poster">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="Title"
android:textSize="20sp" />
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:maxLines="3"
android:text="description"
android:textSize="9sp" />
<TextView
android:id="#+id/main_characters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/description"
android:layout_below="#+id/description"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="characters max 3 people"
android:textSize="13sp" />
<TextView
android:id="#+id/hasSeen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/main_characters"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="has seen?"
android:textSize="11sp" />
</RelativeLayout>
Does anyone have a solution for this one?
This is just a warning, and since it retries without the configuration option without (I am assuming from your comments) a followup error, this is not the source of your problem.
It's not a bad guess, since this is for an OpenGL-related class (android/opengl/EGL14), but it's not the source of your problem.
You can read more about EGL at https://www.khronos.org/egl.
This is my Activity:
public String id;
public String passPhrase;
public ArrayList<SongCell> songs;
private RecyclerView recyclerView;
private MyAdapter myAdapter;
private RecyclerView.LayoutManager layoutManager;
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.songs_view_layout);
Context context = this.getApplicationContext();
Bundle stateData = getIntent().getExtras();
try
{
id = stateData.getString("id");
passPhrase = stateData.getString("passPhrase");
ArrayList data;
recyclerView = (RecyclerView) findViewById(R.id.song_list);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
data = new ArrayList<SongCell>();
for (int i=0; i<5;i++)
{
data.add(new SongCell("Song "+i,"Artist "+i, null));
}
myAdapter = new MyAdapter(data);
recyclerView.setAdapter(myAdapter);
}
catch(Exception e)
{
Log.d("Error: ", e.toString());
}
}
card.xml
<android.support.v7.widget.CardView android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
>
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:id="#+id/song_photo"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
android:background="#drawable/error" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/song_name"
android:textSize="30sp"
android:text="Song Name"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="#000000" />
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/vote_button"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:background="#drawable/arrow" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#2d2d2d">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="30dp"
android:layout_marginBottom="10dp"
android:background="#222222"></TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingBottom="10dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:id="#+id/featSongImage1"
android:contentDescription="#string/newsongimage"
android:background="#drawable/error" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/songname"
android:id="#+id/featSongName1" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/featSongButt1"
android:background="#drawable/arrow"
android:contentDescription="#string/votearrow" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundGravity="fill_horizontal"
android:gravity="fill_horizontal|center">
<android.support.v7.widget.RecyclerView
android:id="#+id/song_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal" />
</TableRow>
</TableLayout>
</LinearLayout>
And this is my custom adapter
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>
{
private ArrayList<SongCell> data;
public MyAdapter(ArrayList<SongCell> dataI)
{
data = dataI;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)
{
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.song_card,viewGroup,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ViewHolder viewholder, int pos) {
viewholder.songName.setText(data.get(pos).getName());
viewholder.artist.setText(data.get(pos).getArtist());
viewholder.image.setImageBitmap(data.get(pos).getArtwork());
}
#Override
public int getItemCount() {
return 0;
}
#Override
public int getItemViewType(int position) {
return 0;
}
public class ViewHolder extends RecyclerView.ViewHolder
{
TextView songName;
TextView artist;
ImageView image;
ImageButton voteButton;
public ViewHolder(View v)
{
super(v);
this.songName = (TextView) v.findViewById(R.id.song_name);
this.image = (ImageView) v.findViewById(R.id.song_photo);
this.voteButton = (ImageButton) v.findViewById(R.id.vote_button);
}
}
}
I have looked at a ton of guides on how to get this working but it still doesn't work. Anyone have any clue what's going on? I'm on version 25.0.1, and have all the modules imported. But it's not adding a single card into the layout.
I thought it would be difficult to debug such a big code you uploaded. But luckily my eye went on this line
#Override
public int getItemCount() {
return 0;
}
return 0; in adapter.
Your list size is always 0.
instead write this
#Override
public int getItemCount() {
return data.size();
}
EDIT-1:
You will also get null pointer exception here
viewholder.artist.setText(data.get(pos).getArtist());
Because you are not initializing the artist variable in ViewHolder class.
Edit-2
#Override
public int getItemCount() {
return 0;
}
you can remove this particular code from your adapter. Because overriding the methods of class that we don't use might sometimes result in errors that you can't even imagine.