Does not show anything in Parsing JSON for Recycler View - android

I follow the online tutorial to build the Parsing JSON for Recycler View application. However, it does not show anything in the application. I don't know what happen about it. Can anyone help me to figure out the problem? Thank you.
enter image description here
MainActivity.java
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
List<net.smallacademy.songslist.Song> songs;
private static String JSON_URL = "http://starlord.hackerearth.com/studio";
Adapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.songsList);
songs = new ArrayList<>();
extractSongs();
}
private void extractSongs() {
RequestQueue queue = Volley.newRequestQueue(this);
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, JSON_URL, null, new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
for (int i = 0; i < response.length(); i++) {
try {
JSONObject songObject = response.getJSONObject(i);
net.smallacademy.songslist.Song song = new net.smallacademy.songslist.Song();
song.setTitle(songObject.getString("song").toString());
song.setArtists(songObject.getString("artists".toString()));
song.setCoverImage(songObject.getString("cover_image"));
song.setSongURL(songObject.getString("url"));
songs.add(song);
} catch (JSONException e) {
e.printStackTrace();
}
}
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
adapter = new Adapter(getApplicationContext(),songs);
recyclerView.setAdapter(adapter);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("tag", "onErrorResponse: " + error.getMessage());
}
});
queue.add(jsonArrayRequest);
}
}
Song.java
public class Song {
private String title;
private String artists;
private String coverImage;
private String songURL;
public Song(){}
public Song(String title,String artists,String coverImage,String songURL){
this.title = title;
this.artists = artists;
this.coverImage = coverImage;
this.songURL = songURL;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArtists() {
return artists;
}
public void setArtists(String artists) {
this.artists = artists;
}
public String getCoverImage() {
return coverImage;
}
public void setCoverImage(String coverImage) {
this.coverImage = coverImage;
}
public String getSongURL() {
return songURL;
}
public void setSongURL(String songURL) {
this.songURL = songURL;
}
}
Adapter.java
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
LayoutInflater inflater;
List<net.smallacademy.songslist.Song> songs;
public Adapter(Context ctx, List<net.smallacademy.songslist.Song> songs) {
this.inflater = LayoutInflater.from(ctx);
this.songs = songs;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.custom_list_layout,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.songTitle.setText(songs.get(position).getTitle());
holder.songArtists.setText(songs.get(position).getArtists());
Picasso.get().load(songs.get(position).getCoverImage()).into(holder.songCoverImage);
}
#Override
public int getItemCount() {
return songs.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView songTitle, songArtists;
ImageView songCoverImage;
public ViewHolder(#NonNull View itemView) {
super(itemView);
songTitle = itemView.findViewById(R.id.songTitle);
songArtists = itemView.findViewById(R.id.songArtist);
songCoverImage = itemView.findViewById(R.id.coverImage);
}
}
}
activity_main.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=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/songsList"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
custom_list_layout.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="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/coverImage"
android:layout_width="75dp"
android:layout_height="75dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_background"
tools:ignore="VectorDrawableCompat" />
<TextView
android:id="#+id/songTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="Song Title"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/coverImage"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:layout_marginLeft="16dp" />
<TextView
android:id="#+id/songArtist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Song Artist"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/coverImage"
app:layout_constraintTop_toBottomOf="#+id/songTitle"
android:layout_marginLeft="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

Please transfer this below code into onCreate method
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
and then change this both tag of Recyclerview
android:layout_width="match_parent"
android:layout_height="wrap_content"

Related

UI bug while updating recycler view

I'm using FirebaseUI FirestorePagingAdapter for recycler view adapter and the recycler view uses GridLayout type with 2 columns . The recycler view item block cantains 1 image view and few others textView , when I scroll down the list and scroll back up top the image view size decreases , this bug continues every time I scroll down and back up .
It also happens when I update the adapter .
Below is the code for it . Btw I'm using Navigation Component UI.
private FirestorePagingAdapter<ProductModel, HomePagingHolder> pagingAdapter;
private FirestorePagingOptions<ProductModel> pagingOptions;
private final PagingConfig config = new PagingConfig(15, 10, false);
POJO class
public class ProductModel {
private boolean availability;
private DocumentReference category_reference;
private boolean customizable;
private String delivery_fee;
private String description;
private String max_order_quantity;
private String name;
private String price;
private List<String> thumbnails;
private String productID;
public ProductModel(){}
public ProductModel(boolean availability, DocumentReference category_reference, boolean customizable,
String delivery_fee, String description, String max_order_quantity, String name, String price, List<String> thumbnails) {
this.availability = availability;
this.category_reference = category_reference;
this.customizable = customizable;
this.delivery_fee = delivery_fee;
this.description = description;
this.max_order_quantity = max_order_quantity;
this.name = name;
this.price = price;
this.thumbnails = thumbnails;
}
public boolean isAvailability() {
return availability;
}
public void setAvailability(boolean availability) {
this.availability = availability;
}
public DocumentReference getCategory_reference() {
return category_reference;
}
public void setCategory_reference(DocumentReference category_reference) {
this.category_reference = category_reference;
}
public String getProductID() {
return productID;
}
public void setProductID(String productID) {
this.productID = productID;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return name;
}
public boolean isCustomizable() {
return customizable;
}
public void setCustomizable(boolean customizable) {
this.customizable = customizable;
}
public String getDelivery_fee() {
return delivery_fee;
}
public void setDelivery_fee(String delivery_fee) {
this.delivery_fee = delivery_fee;
}
public String getMax_order_quantity() {
return max_order_quantity;
}
public void setMax_order_quantity(String max_order_quantity) {
this.max_order_quantity = max_order_quantity;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public List<String> getThumbnails() {
return thumbnails;
}
public void setThumbnails( List<String> thumbnails) {
this.thumbnails = thumbnails;
}
}
ViewHolder class
static class HomePagingHolder extends RecyclerView.ViewHolder {
private final TextView pName;
private final TextView pPrice;
private final ImageView pImg;
private final TextView pThumbnailCount;
public HomePagingHolder(#NonNull View itemView) {
super(itemView);
pName = itemView.findViewById(R.id.productName);
pPrice = itemView.findViewById(R.id.productPrice);
pImg = itemView.findViewById(R.id.productImg);
pThumbnailCount = itemView.findViewById(R.id.thumbnail_count_txt);
}
}
Inside the Fragment
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
...
...
if (pagingOptions == null) {
getProductFromFireStore(false);
initFirestoreUIAdapter();
}
}
Getting the data
private void getProductFromFireStore(boolean check) {
pagingOptions = new FirestorePagingOptions.Builder<ProductModel>().setLifecycleOwner(this).setQuery(productCollection,
config, snapshot -> {
ProductModel model = snapshot.toObject(ProductModel.class);
if (model != null) {
model.setProductID(snapshot.getId());
}
return Objects.requireNonNull(model);
}).build();
if (check) {
pagingAdapter.updateOptions(pagingOptions);
}
}
productCollection inside the setQuery(...) points to a Collection reference inside Firestore.
Adapter
private void initFirestoreUIAdapter() {
pagingAdapter = new FirestorePagingAdapter<ProductModel, HomePagingHolder>(pagingOptions) {
#Override
protected void onBindViewHolder(#NonNull HomePagingHolder holder, int position, #NonNull ProductModel model) {
holder.pName.setText(model.getName());
holder.pPrice.setText(String.format("%s %s", getResources().getString(R.string.rupee_symbol), model.getPrice()));
holder.pThumbnailCount.setText(String.valueOf(model.getThumbnails().size()));
Glide.with(requireContext()).load(model.getThumbnails().get(0)).into(holder.pImg);
holder.itemView.setOnClickListener(view -> {
bundle.putString(Fire.FIELD_PRODUCT_ID, model.getProductID());
NavHostFragment.findNavController(HomeFragment.this).navigate(R.id.action_home_to_productFragment2, bundle);
});
}
#NonNull
#Override
public HomePagingHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(requireContext()).inflate(R.layout.block_home_product_item, parent, false);
return new HomePagingHolder(v);
}
};
}
Recycler view item block
<?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"
android:background="#drawable/product_item_ripple"
android:clickable="true"
android:focusable="true">
<com.google.android.material.card.MaterialCardView
android:id="#+id/imgCard"
android:layout_width="180dp"
android:layout_height="220dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:cardBackgroundColor="#color/colorSurface"
app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<ImageView
android:id="#+id/productImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="#color/colorSurface"
android:src="#drawable/log_in_lounge_bg"
tools:ignore="ContentDescription" />
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/thumbnail_count_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/white_txt_bg"
android:drawablePadding="4dp"
android:elevation="4dp"
android:fontFamily="#font/nunito"
android:text="3"
app:drawableEndCompat="#drawable/ic_multiple_image" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="#+id/productName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:fontFamily="#font/montserrat"
android:maxLines="2"
android:text="Arm chair blue color"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="#+id/imgCard"
app:layout_constraintStart_toStartOf="#+id/imgCard"
app:layout_constraintTop_toBottomOf="#+id/imgCard" />
<TextView
android:id="#+id/productPrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito"
android:text="TextView"
android:textColor="#color/colorTextMini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/productName"
app:layout_constraintStart_toStartOf="#+id/productName"
app:layout_constraintTop_toBottomOf="#+id/productName" />
</androidx.constraintlayout.widget.ConstraintLayout>
Item block
<?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"
android:background="#drawable/product_item_ripple"
android:clickable="true"
android:focusable="true">
<com.google.android.material.card.MaterialCardView
android:id="#+id/imgCard"
android:layout_width="180dp"
android:layout_height="220dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:cardBackgroundColor="#color/colorSurface"
app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/productImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_centerInParent="true"
android:background="#color/colorSurface"
android:src="#drawable/log_in_lounge_bg"
app:shapeAppearance="#style/IsthmusShapeableImageStyle"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/thumbnail_count_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/white_txt_bg"
android:drawablePadding="4dp"
android:elevation="4dp"
android:fontFamily="#font/nunito"
tools:text="3"
app:drawableEndCompat="#drawable/ic_multiple_image" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="#+id/productName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:fontFamily="#font/montserrat"
android:maxLines="2"
tools:text="Arm chair blue color"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="#+id/imgCard"
app:layout_constraintStart_toStartOf="#+id/imgCard"
app:layout_constraintTop_toBottomOf="#+id/imgCard" />
<TextView
android:id="#+id/productPrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito"
tools:text="TextView"
android:textColor="#color/colorTextMini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/productName"
app:layout_constraintStart_toStartOf="#+id/productName"
app:layout_constraintTop_toBottomOf="#+id/productName" />
</androidx.constraintlayout.widget.ConstraintLayout>

Child RecyclerView inside Parent RecyclerView is showing at End of Parent RecyclerView?

Child RecyclerView inside Parent RecyclerView is showing at End of Parent RecyclerView ?
I Want To Show Categroy in Parent RecyclerView & show its Sub Category in Child RecyclerView
But When I Click Parent RecyclerView To Show That Sub Category the Child RecyclerView is showing at The Full End Of Parent Category Please Check Where Is I'm Wrong?
Here is My Results:
First Item Clicked
.
Second Item Clicked
My Code:
This Is My Main Layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".USER.Category">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Category"/>
</LinearLayout>
This is my Main java File:
public class Category extends AppCompatActivity {
static Toast Toasts;
RecyclerView Category;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category);
Category = findViewById(R.id.Category);
Category.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
Category_View_request();
}
public void Category_View_request() {
RequestQueue requestQueue = Volley.newRequestQueue(Category.this);
String url = Constant.Category;
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
GridView_listItems[] Category_View_response = gson.fromJson(response, GridView_listItems[].class);
Category.setAdapter(new CategoryView_Adapter(Category.this, Category_View_response));
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toasts = Toast.makeText(Category.this, "ERROR: Please Check Internet & Try Again", Toast.LENGTH_SHORT);
Toasts.show();
}
});
requestQueue.add(stringRequest);
}
}
this is Parent Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:id="#+id/layout">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:id="#+id/nameLayout">
<ImageView
android:id="#+id/categoryimage"
android:layout_width="120dp"
android:layout_height="120dp"
android:adjustViewBounds="true"
android:background="#fff"
android:contentDescription="#string/todo"
android:padding="8dp"
android:scaleType="fitXY" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingBottom="8dp">
<Space
android:layout_width="112dp"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingBottom="8dp">
<TextView
android:id="#+id/categoryname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="1dp"
android:singleLine="true"
android:text="#string/test_product_name"
android:textColor="#color/Black"
android:textSize="13sp"
tools:ignore="RtlSymmetry" />
<TextView
android:id="#+id/categorydec"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="1dp"
android:paddingTop="3dp"
android:singleLine="true"
android:text="#string/test_product_description"
android:textColor="#color/common_google_signin_btn_text_light_default"
android:textSize="12sp"
tools:ignore="RtlSymmetry" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/click">
</RelativeLayout>
</RelativeLayout>
<androidx.cardview.widget.CardView
android:id="#+id/subview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:background="#color/White"
android:elevation="8dp"
android:paddingTop="10dp"
>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/subCatview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.cardview.widget.CardView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
This is Parent Adapter:
public class CategoryView_Adapter extends RecyclerView.Adapter<CategoryView_Adapter.CategoryViewHolder> {
Toast Toasts;
private static Context context;
private static GridView_listItems[] data;
public CategoryView_Adapter(Context context, GridView_listItems[] data) {
this.context = context;
this.data = data;
}
#NonNull
#Override
public CategoryViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.category_view, parent, false);
return new CategoryViewHolder(view);
}
#SuppressLint("SetTextI18n")
#Override
public void onBindViewHolder(#NonNull final CategoryViewHolder holder, int position) {
final GridView_listItems CategoryList = data[position];
holder.categoryname.setText(CategoryList.getName());
holder.categorydec.setText(CategoryList.getId());
Glide.with(holder.categoryimage.getContext())
.applyDefaultRequestOptions(new RequestOptions()
.placeholder(R.drawable.product_loading)
.error(R.drawable.product_loading_failed))
.load(Constant.MAINImagUrl + CategoryList.getCategoryLogo().substring(2))
.into(holder.categoryimage);
holder.categoryname.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.layout.setBackgroundColor(ContextCompat.getColor(context, R.color.common_google_signin_btn_text_light_default));
Grid_View_request(CategoryList.getName());
}
});
}
#Override
public int getItemCount() {
return data.length;
}
public static class CategoryViewHolder extends RecyclerView.ViewHolder {
ImageView categoryimage;
TextView categoryname, categorydec;
CardView subview;
RelativeLayout click;
LinearLayout layout;
public static RecyclerView subCatview;
public CategoryViewHolder(#NonNull View itemView) {
super(itemView);
categoryimage = (ImageView) itemView.findViewById(R.id.categoryimage);
categoryname = (TextView) itemView.findViewById(R.id.categoryname);
categorydec = (TextView) itemView.findViewById(R.id.categorydec);
click = (RelativeLayout) itemView.findViewById(R.id.click);
subview = (CardView) itemView.findViewById(R.id.subview);
layout = (LinearLayout) itemView.findViewById(R.id.layout);
subCatview = (RecyclerView) itemView.findViewById(R.id.subCatview);
GridLayoutManager gridLayoutManager = new GridLayoutManager(MyApplication.getAppContext(), 3, GridLayoutManager.VERTICAL, false);
subCatview.setLayoutManager(gridLayoutManager);
}
}
public static void Grid_View_request(final String category) {
RequestQueue requestQueue = Volley.newRequestQueue(MyApplication.getAppContext());
String url = Constant.Sub_Category;
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
if (response.contains("CityGroceryEmptyResponse")) {
Toast.makeText(MyApplication.getAppContext(), "No Sub Category Found", Toast.LENGTH_SHORT).show();
} else {
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
Sub_Category_list[] Sub_Category_list = gson.fromJson(response, Sub_Category_list[].class);
subCatview.setAdapter(new Sub_Category_Adapter(MyApplication.getAppContext(), Sub_Category_list));
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MyApplication.getAppContext(), "ERROR: Please Check Internet & Try Again", Toast.LENGTH_SHORT).show();
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("category", category);
return params;
}
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
requestQueue.add(stringRequest);
}
}
This is My Child Layout:
<androidx.cardview.widget.CardView 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="120dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:orientation="horizontal"
android:elevation="8dp"
app:cardCornerRadius="1dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingBottom="8dp">
<ImageView
android:id="#+id/subCatNameimage"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher" />
<TextView
android:id="#+id/subCatName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/subCatNameimage"
android:layout_marginTop="4dp"
android:gravity="center"
android:maxLength="30"
android:text="menu name"
android:textColor="#color/colorPrimary"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/subCatNameimage" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
This is My Child Adapter:
public class Sub_Category_Adapter extends RecyclerView.Adapter<Sub_Category_Adapter.CategoryViewHolder> {
Toast Toasts;
private static Context context;
private static Sub_Category_list[] data;
public Sub_Category_Adapter(Context context, Sub_Category_list[] data) {
this.context = context;
this.data = data;
final Sub_Category_list SubCategoryList = data[0];
}
#NonNull
#Override
public CategoryViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.gridview_items, parent, false);
return new CategoryViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final CategoryViewHolder holder, final int position) {
final Sub_Category_list SubCategoryList = data[position];
holder.subCatName.setText(SubCategoryList.getSubCategoryName());
Glide.with(holder.subCatNameimage.getContext())
.applyDefaultRequestOptions(new RequestOptions()
.placeholder(R.drawable.product_loading)
.error(R.drawable.product_loading_failed))
.load(Constant.MAINImagUrl + SubCategoryList.getSubCategoryLogo().substring(2))
.into(holder.subCatNameimage);
}
#Override
public int getItemCount() {
return data.length;
}
public static class CategoryViewHolder extends RecyclerView.ViewHolder {
ImageView subCatNameimage;
TextView subCatName;
public CategoryViewHolder(#NonNull View itemView) {
super(itemView);
subCatName = (TextView) itemView.findViewById(R.id.subCatName);
subCatNameimage = (ImageView) itemView.findViewById(R.id.subCatNameimage);
}
}
}
Please Correct Me Where is doing Mistake
Thanks In Advance
You can achieve that requirement by using an expandable recycler view.
There are a lot of libraries you can use to achieve this.
You can use this library.
Or follow this post to achieve this on your own, you might need to make some changes to get the output as per your requirement.
I'am achieve My requirement by using an expandable recycler view
HERE

Empty View on a dynamic RecyclerView

I am retrieving Data from MySQL Database in Android and I am using Recyclerview .I test php file and it is working fine but nothing shows in the activity. I checked every thing and it seems fine, I don't know what is the problem ?
Waiting Activity :
<android.support.v7.widget.RecyclerView
android:id="#+id/recylcerView"
android:layout_width="1dp"
android:layout_height="1dp"
tools:layout_editor_absoluteX="745dp"
tools:layout_editor_absoluteY="51dp" />
</RelativeLayout>
list_layout :
<?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"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="#+id/imageView"
android:layout_width="120dp"
android:layout_height="90dp"
android:padding="4dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:text=" Waiting Time :"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"/>
<TextView
android:id="#+id/textViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/imageView"
android:text="00"
android:layout_marginTop="5dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#000000" />
<TextView
android:id="#+id/textViewRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textViewTime"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/imageView"
android:background="#color/colorPrimary"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="Bus Number : "
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small.Inverse"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewBusNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textViewRating"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/imageView"
android:text="255"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large" />
</RelativeLayout>
</LinearLayout>
WaitingActivity :
public class WaitingActivity extends AppCompatActivity {
private static final String URL_PRODUCTS = "http://192.168.1.2/Android/v1/test1.php";
List<Product> productList;
RecyclerView recyclerView;
ProductsAdapter adapter ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_waiting);
recyclerView = (RecyclerView) findViewById(R.id.recylcerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
private void loadProducts() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL_PRODUCTS,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONArray products = new JSONArray(response);
for (int i = 0; i < products.length(); i++) {
JSONObject productObject = products.getJSONObject(i);
int Temp_dt = productObject.getInt("Temp_dt");
int BusNumber =productObject.getInt("BusNumber");
Product product = new Product(Temp_dt, BusNumber);
productList.add(product);
}
adapter = new ProductsAdapter(WaitingActivity.this, productList);
recyclerView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(WaitingActivity.this, error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
//adding our stringrequest to queue
Volley.newRequestQueue(this).add(stringRequest);
}
Product class :
public class Product {
private int Temp_dt;
private int BusNumber;
public Product(int Temp_dt, int BusNumber) {
this.Temp_dt = Temp_dt;
this.BusNumber = BusNumber ;
}
public int getWaitingTime() {
return Temp_dt;
}
public int getBusNumber() {
return BusNumber ;
}
}
ProductAdapter :
public class ProductsAdapter extends
RecyclerView.Adapter<ProductsAdapter.ProductViewHolder> {
private Context mCtx;
private List<Product> productList;
public ProductsAdapter(Context mCtx, List<Product> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
#Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//inflating and returning our view holder
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.list_layout, null);
return new ProductViewHolder(view);
}
#Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
Product product = productList.get(position);
holder.textViewTime.setText(String.valueOf(product.getWaitingTime()));
holder.textViewBusNumber.setText(String.valueOf(product.getBusNumber()));
}
#Override
public int getItemCount() {
return productList.size();
}
class ProductViewHolder extends RecyclerView.ViewHolder {
TextView textViewTime;
TextView textViewBusNumber;
public ProductViewHolder(View itemView) {
super(itemView);
textViewTime = itemView.findViewById(R.id.textViewTime);
textViewBusNumber = itemView.findViewById(R.id.textViewBusNumber);
}
}
}
I expect to show temp_dt and waiting time from php file but the actual output is nothing just empty activity.

RecyclerView does not show list of objects

I tried the solutions on the other similar posts that I found here but they did not help me. I hope someone can help.
I get data from Unsplash's API and the ArrayList contains 10 items once I get a response, that's why I think It has to be something with the way the view is inflated.
This is code:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "unsplash";
private final String CLIENT_ID = "...myclientID...";
// testing keyword used on the API to search for pictures
private final String KEYWORD = "stackOverflow";
private final String urlBase = "https://api.unsplash.com/";
private Retrofit retrofit;
private RecyclerView recyclerView;
private RecyclerViewAdapter recyclerViewAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
retrofit = new Retrofit.Builder()
.baseUrl(urlBase)
.addConverterFactory(GsonConverterFactory.create())
.build();
recyclerView = findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(layoutManager);
recyclerViewAdapter = new RecyclerViewAdapter();
recyclerView.setAdapter(recyclerViewAdapter);
getData();
}
private void getData() {
PictureService service = retrofit.create(PictureService.class);
Call<PictureResponse> pictureResponseCall = service.getPictureList(KEYWORD, CLIENT_ID);
pictureResponseCall.enqueue(new Callback<PictureResponse>() {
#Override
public void onResponse(Call<PictureResponse> call, Response<PictureResponse> response) {
if (response.isSuccessful()){
PictureResponse pictureResponse = response.body();
ArrayList<UnsplashPic> pictureList = pictureResponse.getResults();
recyclerViewAdapter.addPictures(pictureList);
}else{
Log.e (TAG, " onResponse " + response.errorBody());
}
}
#Override
public void onFailure(Call<PictureResponse> call, Throwable t) {
Log.e (TAG, " onFailure " + t.getMessage());
}
});
}
}
My adapter class:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private ArrayList<UnsplashPic> pictureList;
public RecyclerViewAdapter (){
pictureList = new ArrayList<>();
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_view_holder, viewGroup, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder viewHolder, int i) {
UnsplashPic pic = pictureList.get(i);
viewHolder.artistName.setText(pic.user.getUsername());
viewHolder.unsplash.setText("Unsplash");
}
#Override
public int getItemCount() {
return pictureList.size();
}
public void addPictures(ArrayList<UnsplashPic> pictureList) {
pictureList.addAll(pictureList);
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView imageView;
private TextView artistName;
private TextView unsplash;
public ViewHolder (View itemView){
super(itemView);
imageView = itemView.findViewById(R.id.imageview);
artistName = itemView.findViewById(R.id.artist_name);
unsplash = itemView.findViewById(R.id.unsplash_name);
}
}
}
item_view_holder.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="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="#ababab"
android:contentDescription="unsplash picture" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Photo by "/>
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="on "/>
<TextView
android:id="#+id/unsplash_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
activity_main.xml
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Search for pictures"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recyclerview">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Here:
public void addPictures(ArrayList<UnsplashPic> pictureList) {
pictureList.addAll(pictureList);
notifyDataSetChanged();
}
you are actually adding the content of the pictureList you send as parameter of the function to that same list, your list from adapter is not updated.
You should do like this instead:
public void addPictures(ArrayList<UnsplashPic> pictureList) {
this.pictureList.addAll(pictureList);
notifyDataSetChanged();
}

Recycler View with firebase just displaying the first instance

Hi I ma trying to build an app that has a list of events retrieved from a firebase database but when I run it it displays just the first event stored.
there is the code I used to generate the list:
private RecyclerView recyclerView;
private FirebaseRecyclerAdapter<Event,EventViewHolder> firebaseRecyclerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendario);
recyclerView = (RecyclerView) findViewById(R.id.eventiList);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
Query query = FirebaseDatabase.getInstance().getReference("Eventi");
FirebaseRecyclerOptions<Event> options =
new FirebaseRecyclerOptions.Builder<Event>().setQuery(query, Event.class).build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Event, EventViewHolder>(options) {
#NonNull
#Override
public EventViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.event_layout, parent, false);
return new EventViewHolder(view);
}
#Override
protected void onBindViewHolder(#NonNull EventViewHolder holder, final int position, #NonNull Event model) {
holder.setDay(model.getData().substring(0,2));
holder.setMonth(model.getMese());
holder.setName(model.getNome());
holder.setLuogo(model.getLuogo());
holder.setendStart(model.getOra_inizio()+ " - "+ model.getOra_fine());
holder.mview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
}
public static class EventViewHolder extends RecyclerView.ViewHolder
{
View mview;
public EventViewHolder(View itemView)
{
super(itemView);
mview=itemView;
}
public void setDay(String day)
{
TextView mtext= (TextView)mview.findViewById(R.id.day);
mtext.setText(day);
}
public void setName(String name)
{
TextView maut=(TextView)mview.findViewById(R.id.Event_Name);
maut.setText(name);
}
public void setMonth(String month)
{
TextView maut=(TextView)mview.findViewById(R.id.month);
maut.setText(month);
}
public void setLuogo(String luogo)
{
TextView maut=(TextView)mview.findViewById(R.id.luogo);
maut.setText(luogo);
}
public void setendStart(String endStart)
{
TextView maut=(TextView)mview.findViewById(R.id.start_end);
maut.setText(endStart);
}
}
#Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
//mAdapter.stopListening();
firebaseRecyclerAdapter.stopListening();
}
this is the code of the model class
public class Event {
private String Nome;
private String data;
private String descrizione;
private String luogo;
private String mese;
private String ora_fine;
private String ora_inizio;
private String type;
public Event()
{
}
public Event(String nome, String data, String descrizione, String luogo, String mese, String ora_fine, String ora_inizio, String type) {
Nome = nome;
this.data = data;
this.descrizione = descrizione;
this.luogo = luogo;
this.mese = mese;
this.ora_fine = ora_fine;
this.ora_inizio = ora_inizio;
this.type = type;
}
public String getNome() {
return Nome;
}
public String getData() {
return data;
}
public String getDescrizione() {
return descrizione;
}
public String getLuogo() {
return luogo;
}
public String getMese() {
return mese;
}
public String getOra_fine() {
return ora_fine;
}
public String getOra_inizio() {
return ora_inizio;
}
public String getType() {
return type;
}
}
this is the Calendar activity layout
<android.support.v4.widget.DrawerLayout 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=".Calendario"
android:id="#+id/Calendar_draw">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/eventiList"></android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>
This is the code for the recycler view row
<?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.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="119dp"
android:background="#color/darkBlue">
<TextView
android:id="#+id/day"
android:layout_width="86dp"
android:layout_height="66dp"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/Event_Name"
android:layout_marginStart="18dp"
android:textColor="#color/white"
android:textSize="50dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="18dp" />
<TextView
android:id="#+id/month"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/day"
android:layout_marginBottom="11dp"
android:textColor="#color/white"
android:textStyle="bold"
android:layout_alignLeft="#+id/day" />
<TextView
android:id="#+id/Event_Name"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="124dp"
android:layout_marginTop="13dp"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textColor="#color/white"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:layout_marginLeft="124dp" />
<TextView
android:id="#+id/start_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="135dp"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#color/white"
android:textStyle="italic" />
<TextView
android:id="#+id/luogo"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignStart="#+id/start_end"
android:layout_below="#+id/day"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#color/white"
android:textStyle="italic" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
As you can see from the image that follows it displays just one event and I have 5 in the database
Display
The code worked fine for other lists that are in the app I don't understand why it is not working for this one hope I can get an answer here, thanks
Edit: this is the Database tree
Database Tree
Problem Solved, the layout_height parameter was set to match_parent in the event_layout LinearLayout and CardView. I set it to wrap_content on both and it worked.

Categories

Resources