How to start different activities on click of different recycler views - android

I have a RecyclerView with GridLayoutManager. On click of each Item i want tstart different acticities. I have tried but it is not working. This is my DashboardAdapter class
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.ViewHolder>{
private List<DashboardPojo> countries;
private int rowLayout;
private Context mContext;
public DashboardAdapter(List<DashboardPojo> countries, int rowLayout, Context context) {
this.countries = countries;
this.rowLayout = rowLayout;
this.mContext = context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
DashboardPojo country = countries.get(i);
viewHolder.countryName.setText(country.name);
viewHolder.countryImage.setImageResource(country.getImageResourceId(mContext));
}
#Override
public int getItemCount() {
return countries == null ? 0 : countries.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView countryName;
public ImageView countryImage;
public ViewHolder(View itemView) {
super(itemView);
mContext = itemView.getContext();
itemView.setOnClickListener(this);
countryName = (TextView) itemView.findViewById(R.id.countryName);
countryImage = (ImageView)itemView.findViewById(R.id.countryImage);
}
#Override
public void onClick(View v) {
final Intent intent;
if (getPosition() == 0){
intent = new Intent(mContext, TutorialActivity.class);
} else if (getPosition() == 1){
intent = new Intent(mContext, JobsActivity.class);
} else {
intent = new Intent(mContext, TutorialActivity.class);
}
mContext.startActivity(intent);
}
}
}
And in my DashBoardActivity i have
mRecyclerView = (RecyclerView) findViewById(R.id.list);
mLayoutManager = new GridLayoutManager(this, 2);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mAdapter = new DashboardAdapter(DashboardManager.getInstance().getCountries(), R.layout.dashboard_row, this);
mRecyclerView.setAdapter(mAdapter);
And is dashboard_row.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_margin="5dp"
card_view:cardCornerRadius="5dp"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/countryImage"
android:layout_width="match_parent"
android:layout_height="120dp"
android:scaleType="centerCrop"
android:tint="#color/photo_tint"
android:layout_centerInParent="true"
/>
<TextView
android:id="#+id/countryName"
android:gravity="center"
android:background="?android:selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="100dp"
android:textSize="24sp"
android:layout_centerInParent="true"
android:textColor="#android:color/white"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
activity_dashboard.xml
<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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rel"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DashBoardActivity"
android:layout_below="#+id/app_bar"
android:layout_marginTop="20dp"/>
</RelativeLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="solutions.techieweb.com.techiewebsolutions.NavigationDrawerFragment"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Please help me....

From what u have posted it seems that your View onClick() event is consumed by TextView
Please remove the :
android:focusable="true"
android:clickable="true"
tag from countryname TextView
And also change getPosition() to getAdapterPosition() as getPosition() is deprecated

Try This:
v.getContext().startActivity(intent);
Instead of:
mContext.startActivity(intent);

Related

Unable to Align 2 Cardviews Vertically Inside RecyclerView

I have 2 CardViews and a RecyclerView but i am
unable to align them vertically
unable to slide them independently (both slide if I slide any one in a bugged workaround)
I tried a few workarounds as well as different tutorials like edmt Dev and CodingWithMitch as well as searched for similar problems on stackoverflow but the problem seems to persist. So how do I align both of the cardviews vertically while still being able to slide each of them independently and horizontally.
(Code works fine for single card view)
Main Activity:
public class MainActivity extends AppCompatActivity {
List<Articles> articlesData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
articlesData = new ArrayList<>();
//Repeats
articlesData.add(new Articles("10 Necessary Gadgets","Gadgets","Gadgets You Must Carry",R.drawable.bagchaincustom));
articlesData.add(new Articles("10 Benefits of Pre-Planning the Day","Self Improvement","Benefits of Planning in Advance",R.drawable.planner1custom));
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false);
RecyclerView recyclerView = findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(layoutManager);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, articlesData);
recyclerView.setAdapter(adapter);
}
Here is 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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recyclerview"
android:orientation="horizontal">
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>
Here is the RecyclerViewAdapter Class:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int LAYOUT_ONE= 0;
private static final int LAYOUT_TWO= 1;
#Override
public int getItemViewType(int position)
{
if(position == LAYOUT_ONE){
return LAYOUT_TWO;
}
else {
return LAYOUT_ONE;
}
}
private static final String Tag = "RecyclerViewAdapter";
private Context mContext;
private List<Articles> mData;
public RecyclerViewAdapter(Context mContext, List<Articles> mData) {
this.mContext = mContext;
this.mData = mData;
}
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater mInflater = LayoutInflater.from(mContext);
View view;
switch (viewType) {
case 0:
ViewHolder1 viewHolder1;
view = mInflater.inflate(R.layout.layout_listitem, parent, false);
return new ViewHolder1(view);
case 1:
ViewHolder2 viewHolder2;
view = mInflater.inflate(R.layout.layout_listitem2, parent, false);
return new ViewHolder2(view);
default:
return null;
}
}
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, final int position) {
switch (holder.getItemViewType()){
case 0:
ViewHolder1 viewHolder1 = (ViewHolder1)holder;
viewHolder1.tv_article_title.setText(mData.get(position).getTitle());
viewHolder1.img_article_thumbnail.setImageResource(mData.get(position).getThumbnail());
viewHolder1.cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(mContext, ArticlesActivity.class);
intent.putExtra("Title", mData.get(position).getTitle());
intent.putExtra("Description", mData.get(position).getDescription());
intent.putExtra("Thumbnail", mData.get(position).getThumbnail());
intent.putExtra("Category", mData.get(position).getCategory());
mContext.startActivity(intent);
}
});
break;
case 1:
ViewHolder2 viewHolder2 = (ViewHolder2)holder;
viewHolder2.tv_article_title2.setText(mData.get(position).getTitle());
viewHolder2.img_article_thumbnail2.setImageResource(mData.get(position).getThumbnail());
viewHolder2.cardView2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(mContext, ArticlesActivity.class);
intent.putExtra("Title", mData.get(position).getTitle());
intent.putExtra("Description", mData.get(position).getDescription());
intent.putExtra("Thumbnail", mData.get(position).getThumbnail());
intent.putExtra("Category", mData.get(position).getCategory());
mContext.startActivity(intent);
}
});
break;
}
}
#Override
public int getItemCount() {
return mData.size();
}
public class ViewHolder1 extends RecyclerView.ViewHolder{
TextView tv_article_title;
ImageView img_article_thumbnail;
CardView cardView;
public ViewHolder1(#NonNull View itemView) {
super(itemView);
tv_article_title = (TextView) itemView.findViewById(R.id.article_title_id);
img_article_thumbnail = (ImageView) itemView.findViewById((R.id.article_image_id));
cardView = (CardView) itemView.findViewById(R.id.cardview_id);
}
}
public class ViewHolder2 extends RecyclerView.ViewHolder{
TextView tv_article_title2;
ImageView img_article_thumbnail2;
CardView cardView2;
public ViewHolder2(#NonNull View itemView) {
super(itemView);
tv_article_title2 = (TextView) itemView.findViewById(R.id.article_title_id2);
img_article_thumbnail2 = (ImageView) itemView.findViewById((R.id.article_image_id2));
cardView2 = (CardView) itemView.findViewById(R.id.cardview_id2);
}
}
}
Here is the Articles Class:
public class Articles {
private String Title;
private String Category;
private String Description;
private int Thumbnail;
public Articles(String title, String category, String description, int thumbnail) {
Title = title;
Category = category;
Description = description;
Thumbnail = thumbnail;
}
public String getTitle() {
return Title;
}
public String getCategory() {
return Category;
}
public String getDescription() {
return Description;
}
public int getThumbnail() {
return Thumbnail;
}
And here is the CardView -> layout_listitem Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_alignParentStart="true"
android:id="#+id/rview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="#+id/cardview_id"
android:layout_width="120dp"
android:layout_height="220dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<ImageView
android:id="#+id/article_image_id"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#2d2d2d"
android:scaleType="centerCrop"></ImageView>
<TextView
android:id="#+id/article_title_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Article Name"
android:textSize="14sp">
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
And here is the CardView -> layout_listitem2 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:card_view="http://schemas.android.com/tools"
android:layout_alignParentStart="true"
android:id="#+id/rview2"
android:layout_below="#+id/rview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="300dp">
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="#+id/cardview_id2"
android:layout_below="#id/cardview_id"
android:layout_width="120dp"
android:layout_height="220dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_marginTop="250dp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<ImageView
android:id="#+id/article_image_id2"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#2d2d2d"
android:scaleType="centerCrop"></ImageView>
<TextView
android:id="#+id/article_title_id2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Article Name Sec"
android:textSize="14sp">
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
ConstraintLayout is not a scrolling parent, so it will create problem if you add a long RecyclerView inside it.
So I made a few modifications to the above code and it has solved the both problems (Independent sliding and vertical alignment)
I have added another recyclerview in main_activity.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"
tools:context=".MainActivity"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView
android:layout_below="#+id/recyclerview_id2"
android:layout_marginTop="10dp"
android:id="#+id/recyclerview_id2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="NotSibling">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
I have also created another Adapter for the new recyclerview, seperated classes for both viewholders as well as removed the switch statements and itemViewType from RecyclerViewAdapter and RecyclerViewAdapter2 class :
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view;
LayoutInflater mInflater = LayoutInflater.from(mContext);
view = mInflater.inflate(R.layout.layout_listitem2,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, final int position) {
holder.tv_article_title2.setText(mData.get(position).getTitle());
holder.img_article_thumbnail2.setImageResource(mData.get(position).getThumbnail());
holder.cardView2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(mContext,ArticlesActivity.class);
intent.putExtra("Title",mData.get(position).getTitle());
intent.putExtra("Description",mData.get(position).getDescription());
intent.putExtra("Thumbnail",mData.get(position).getThumbnail());
intent.putExtra("Category",mData.get(position).getCategory());
mContext.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return mData.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder{
TextView tv_article_title2;
ImageView img_article_thumbnail2;
CardView cardView2;
public ViewHolder(#NonNull View itemView) {
super(itemView);
tv_article_title2 = (TextView) itemView.findViewById(R.id.article_title_id2);
img_article_thumbnail2 = (ImageView) itemView.findViewById((R.id.article_image_id2));
cardView2 = (CardView) itemView.findViewById(R.id.cardview_id2);
}
}
I also edited the main_acitivty class by adding the new recyclerview and layout manager at the end:
LinearLayoutManager layoutManager2 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false);
RecyclerView recyclerView2 = findViewById(R.id.recyclerview_id2);
recyclerView2.setLayoutManager(layoutManager2);
RecyclerViewAdapter2 adapter2 = new RecyclerViewAdapter2(this, articlesData);
recyclerView2.setAdapter(adapter2);
Even though this workaround fixes both problems i was facing is there any other better/more refined way of doing this (eg by using single recyclerview) and where did i made the mistake in previous approach?

Tool bar is disappearing when applying recyclerviewer

I have this method when its called the toolbar is disappearing(the text of recycler is being on top of it), when i comment the method it the toolbar is visible.
can you help to the resolve it?
private void initViews() {
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.card_recycler_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
mydb = new DbHandler(this);
ArrayList<ListMainItem> listmainitem = mydb.getAllItemss("N");
ArrayList<ListMainItem> listmainitemheader = mydb.getAllItemss("Y");
MainItemsRCVAdapter mainitemadRCVapter = new MainItemsRCVAdapter(MainActivity.this, listmainitem, listmainitemheader);
recyclerView.setAdapter(mainitemadRCVapter);
}
this is the main activity
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/app_bar_main"/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
this is mainitem header
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:background="#color/colorPrimaryDark"
android:layout_height="255dp">
<TextView
android:id="#+id/toptext"
android:layout_width="match_parent"
android:layout_height="35dp"
android:textSize="23dp"
android:text="New Games"
android:background="#color/colorAccent"
android:textColor="#color/colorText"
android:gravity="center"
android:layout_weight="0.7"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_horizontal"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="185dp"
android:layout_below="#+id/toptext"
android:paddingTop="8dp">
</android.support.v7.widget.RecyclerView>
<TextView
android:id="#+id/bottomtext"
android:layout_width="match_parent"
android:layout_height="35dp"
android:textSize="23dp"
android:text="Used Games"
android:layout_below="#+id/recycler_view_horizontal"
android:background="#color/colorAccent"
android:textColor="#color/colorText"
android:gravity="center" />
</RelativeLayout>
this is the Mainitemrecyclerview adapter
public class MainItemsRCVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context mContext;
private ArrayList<ListMainItem> itemMain;
private ArrayList<ListMainItem> itemHeader;
private static final int TYPE_HEADER = 0;
private static final int TYPE_ITEM = 1;
public MainItemsRCVAdapter( Context context ,ArrayList<ListMainItem> listMainItem ,ArrayList<ListMainItem> listMainItemHeader) {
setItemHeader(listMainItemHeader);
setItemMain(listMainItem);
mContext = context;
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_ITEM) {
//inflate your layout and pass it to view holder
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_item_adapter, parent, false);
MainItemsViewholder vh = new MainItemsViewholder(v, new MainItemsViewholder.IMyViewHolderClicks() {
public void onPotato(View caller) { Log.d("VEGETABLES", "Poh-tah-tos");
Intent intent = new Intent(mContext,SingleItemActivity.class);
mContext.startActivity(intent);
};
public void onTomato(ImageView callerImage) {
Log.d("VEGETABLES", "To-m8-tohs");
Intent intent = new Intent(mContext,SingleItemActivity.class);
mContext.startActivity(intent);
}
});
return new MyViewHolder(v);
} else if (viewType == TYPE_HEADER) {
//inflate your layout and pass it to view holder
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_item_header, parent, false);
return new MyViewHolderHeader(v);
}
throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof MyViewHolder) {
String name = getItemMain().get(position-1).geImgName();
Integer price = getItemMain().get(position-1).getPrice();
String convert_price = "Price: " + price.toString() + "$";
Log.d("###", "Setting name: " + name);
Log.d("###", "Setting URL " + name);
Log.d("###", "Setting price " + price + "p" + convert_price);
((MyViewHolder) holder).getmDataTextView().setText(name);
((MyViewHolder) holder).getmPriceTextView().setText(convert_price);
/* Picasso.with(mContext)
.load(R.drawable.img1)
.into(((MyViewHolder) holder).getmDataImageView());*/
Picasso.with(mContext)
.load(R.drawable.ww2)
.into(((MyViewHolder) holder).getmDataImageView());
} else if (holder instanceof MyViewHolderHeader) {
//cast holder to VHHeader and set data for header.
Log.d("####", "HEADER");
}
}
private class MyViewHolder extends RecyclerView.ViewHolder {
private TextView mDataTextView;
private TextView mPriceTextView;
private ImageView mDataImageView;
private RecyclerView mainViewRecyclerViewItems;
public MyViewHolder(View v) {
super(v);
/* mainViewRecyclerViewItems = (RecyclerView) v.findViewById(R.id.main_recycler_view);
MainItemsAdapter mAdapter = new MainItemsAdapter(getDataHorizontal(),mContext);
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
mainViewRecyclerViewItems.setLayoutManager(layoutManager);
mainViewRecyclerViewItems.setAdapter(mAdapter);*/
mDataTextView = (TextView) v.findViewById(R.id.gamename_mg);
mPriceTextView=(TextView) v.findViewById(R.id.price_mg);
mDataImageView = (ImageView) v.findViewById(R.id.img_mg);
}
public TextView getmPriceTextView() {
return mPriceTextView;
}
public TextView getmDataTextView() {
return mDataTextView;
}
public ImageView getmDataImageView()
{
return mDataImageView;
}
}
private class MyViewHolderHeader extends RecyclerView.ViewHolder {
private final RecyclerView mHeaderRecyclerView;
public MyViewHolderHeader(View v) {
super(v);
mHeaderRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view_horizontal);
HeaderItemsAdapter mAdapter = new HeaderItemsAdapter(getItemHeader(),mContext);
LinearLayoutManager layoutManager
= new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
mHeaderRecyclerView.setLayoutManager(layoutManager);
mHeaderRecyclerView.setAdapter(mAdapter);
}
}
#Override
public int getItemCount() {
return itemMain.size() + 1;
}
#Override
public int getItemViewType(int position) {
if (isPositionHeader(position)) {
return TYPE_HEADER;
}
return TYPE_ITEM;
}
private boolean isPositionHeader(int position) {
return position == 0;
}
public void setItemMain(ArrayList<ListMainItem> itemmain) {
this.itemMain = itemmain;
}
public void setItemHeader(ArrayList<ListMainItem> itemheader) {
this.itemHeader = itemheader;
}
public ArrayList<ListMainItem> getItemHeader() {
return itemHeader;
}
public ArrayList<ListMainItem> getItemMain() {
return itemMain;
}
}
edit:
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<!-- <include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"/>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
The way DrawerLayout works - inside it you'll define two layouts. The first one will be used as your main content, the second one is the content of the drawer.
When you declare a frame layout as your content and put the toolbar and the recycler view in there, they overlap (same thing would happen even without the drawer). From Android documentation on FrameLayout: "Child views are drawn in a stack, with the most recently added child on top."
Replace your FrameLayout with RelativeLayout (you even have android:layout_below="#+id/toolbar" already) or LinearLayout and it should work.

RecyclerView wont display data

I am using RecyclerView to show some data in form of list, but the data won't display.
Following is my code, I am using to implement RecyclerView
public class MainActivity extends AppCompatActivity implements SearchView.OnQueryTextListener{
String[] c_names={"INDIA","US","UK","AUSTRALIA","CHINA","JAPAN"};
int[] c_flags={R.drawable.india,R.drawable.india,R.drawable.india,R.drawable.india,R.drawable.india,R.drawable.india};
private RecyclerView recyclerView;
RecyclerAdapter recyclerAdapter;
ArrayList<Country> arrayList=new ArrayList<>();
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView=findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
recyclerView.setHasFixedSize(true);
int count=0;
for(String Name:c_names){
arrayList.add(new Country(Name,c_flags[count]));
Log.i("ggg", "onCreate: "+arrayList.get(count).getName()+" "+arrayList.get(count).getFlag_id());
count++;
}
recyclerAdapter=new RecyclerAdapter(arrayList);
recyclerView.setAdapter(recyclerAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
MenuItem menuItem=menu.findItem(R.id.ction_search);
SearchView searchView= (SearchView) MenuItemCompat.getActionView(menuItem);
searchView.setOnQueryTextListener(this);
return true;
}
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
newText=newText.toLowerCase();
ArrayList<Country> newList=new ArrayList<>();
for(Country country:arrayList){
String name=country.getName().toLowerCase();
if(name.contains(newText)){
newList.add(country);
}
}
recyclerAdapter.setFilter(newList);
return true;
}
}
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> {
ArrayList<Country> arrayList=new ArrayList<>();
public RecyclerAdapter(ArrayList<Country> arrayList) {
this.arrayList = arrayList;
}
#Override
public RecyclerAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout,
parent,false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(RecyclerAdapter.MyViewHolder holder, int position) {
holder.c_flags.setImageResource(arrayList.get(position).getFlag_id());
holder.c_name.setText(arrayList.get(position).getName());
}
#Override
public int getItemCount() {
return arrayList.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder{
ImageView c_flags;
TextView c_name;
public MyViewHolder(View itemView) {
super(itemView);
c_flags=itemView.findViewById(R.id.flag);
c_name=itemView.findViewById(R.id.name);
}
}
public void setFilter(ArrayList<Country> filter){
// filter=new ArrayList<>();
arrayList.addAll(filter);
notifyDataSetChanged();
}
}
activity_main
<?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="pritish.sawant.com.filterrecyclerview.MainActivity">
<include layout="#layout/toolbar_layout"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recyclerview"/>
</LinearLayout>
row_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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="4dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="4dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:elevation="5dp"
app:cardCornerRadius="8dp"
android:background="#9E9E9E"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="#9E9E9E">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="8dp"
android:scaleType="fitXY"
android:id="#+id/flag"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/flag"
android:layout_marginLeft="20dp"
android:gravity="center"
android:layout_centerVertical="true"
android:textSize="15dp"
android:textStyle="bold"
android:id="#+id/name"
android:textColor="#000000"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
toolbar_layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimary"
android:id="#+id/toolbar"
app:theme="#style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
My RecyclerView is blank.
I am showing the arrays mentioned in MainActivity in my RecyclerView. I tried a lot but couldn't figure out what am I doing wrong? Any help would be greatly appreciated.
You are missing orientation in parent layout.
<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:orientation="vertical"
android:layout_height="match_parent"
tools:context="pritish.sawant.com.filterrecyclerview.MainActivity">
<include layout="#layout/toolbar_layout"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recyclerview"/>
</LinearLayout>

onCreateViewHolder not called RecyclerView

I am using Recyclerview and my onCreateViewHolder and onBindViewHolder are not called. I am getting the data but it is not displaying.
My adapter class
public class DishesAdapter extends RecyclerView.Adapter<DishesAdapter.MyViewHolder> {
private Context mContext;
List<List> DialogList = new ArrayList<List>();
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView dishnames;
public RatingBar dishratings;
public ImageView dishimages;
private ImageLoader mLoader;
public MyViewHolder(View view) {
super(view);
Log.d("follower2","hi");
dishnames = (TextView)view.findViewById(R.id.dishname);
dishimages = (ImageView)view.findViewById(R.id.dishimage);
dishratings=(RatingBar)view.findViewById(R.id.dishrating);
}
}
public DishesAdapter(Context mContext, List objects) {
super();
Log.d("follower1","hi");
this.mContext = mContext;
this.DialogList = objects;
Log.d("follower1",objects.toString());
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(mContext)
.inflate(R.layout.recipe_list, parent, false);
Log.d("follower","hi");
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
final int i=position;
Log.d("follower","hi");
List dialog = DialogList.get(i);
Log.d("follower",dialog.toString());
String dishid = dialog.get(0).toString();
final String dishname = dialog.get(1).toString();
//byte[] dishimage = Base64.decode(dialog.get(2).toString(), Base64.DEFAULT);
String dishimage=dialog.get(2).toString();
String rating=dialog.get(3).toString();
holder.dishnames.setText(dishname);
holder.dishratings.setRating(Float.parseFloat(rating));
holder.mLoader.DisplayImage(dishimage.replaceAll(" ", "%20"),holder.dishimages);
}
#Override
public int getItemCount() {
return DialogList.size();
}}
Recyclerview
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(mLayoutManager);
xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
tools:context="mealplanner.com.main.mealplanner.MainActivity"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />
</LinearLayout>
Row List
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="3dp"
android:id="#+id/cv">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/dishimage"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginRight="6dip"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_margin="10dp"
android:src="#drawable/portraitlanding"
/>
<TextView
android:id="#+id/dishname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_toRightOf="#+id/dishimage"
android:textColor="#000000"
android:textSize="20dp"
android:layout_gravity="center"
android:text="Andrew" />
<RatingBar
android:id="#+id/dishrating"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.1"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_below="#+id/dishname"
android:layout_toRightOf="#+id/dishimage"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
DishesAdapter constructor is being called. I am getting follower1 log along with the list of items.

RecyclerVIew is not recycling CardView containing images and text inside NestedScrollView

I am using 3 recyclerView inside a nestedScrolView, first 2 are GridView and the 3rd one is LinearLayout.
Now as I am scrolling through few items 3rd recycler view shows laggy behavior, and I have a hunch that items are not recycled.
And I think that it's also affecting(laggy behavior) my Navigation Drawer(opening and closing)
Below is my code
#Override
protected void onPostExecute(Void aVoid) {
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
recyclerView = (RecyclerView) view.findViewById(R.id.feeds_recyclerView);
recyclerView.setNestedScrollingEnabled(false);
mLayoutManager = new LinearLayoutManager(getContext());
load = new FeedAdapter(getActivity(), worldpopulationlist);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setHasFixedSize(true);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(load);
progressBar.setVisibility(View.GONE);
viewMore.setVisibility(View.VISIBLE);
viewMore.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new LoadMoreDataTask().execute();
}
});
}
NestedScrollView XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="#color/turquoise"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:scrimVisibleHeightTrigger="180dp">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="?attr/actionBarSize"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/turquoise"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_grey"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="#+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<FrameLayout
android:id="#+id/mainContainer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
</FrameLayout>
<FrameLayout
android:id="#+id/mainContainer3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
</FrameLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Inflated Single Row Xml
<FrameLayout 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="Fragment.Feeds">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/feeds"
android:textColor="#color/turquoise"
android:textSize="20sp"
android:textStyle="bold" />
<ImageView
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/grey" />
<android.support.v7.widget.RecyclerView
android:id="#+id/feeds_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
<TextView
android:id="#+id/view_more"
style="#style/Base.TextAppearance.AppCompat.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="View More"
android:textColor="#color/turquoise" />
<ProgressBar
android:id="#+id/progressBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
3rd Adapter
public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.MyViewHolder> {
View itemView;
private View nativeExpressLayoutView;
private View itemView1;
private Context context;
private List<WorldPopulation> worldpopulationlist = null;
private WorldPopulation movie;
private int x;
private AdRequest adRequest = new AdRequest.Builder()
.build();
public FeedAdapter(FragmentActivity feeds, List<WorldPopulation> worldpopulationlist) {
this.context = feeds;
this.worldpopulationlist = worldpopulationlist;
ArrayList<WorldPopulation> arraylist = new ArrayList<>();
arraylist.addAll(worldpopulationlist);
}
#Override
public int getItemViewType(int position) {
movie = worldpopulationlist.get(position);
if (movie.getAds() == 1) {
return 1;
} else if (movie.getAds()==0){
return 0;
} else if(movie.getAds()==2){
return 2 ;
}
return 1;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case 1:
itemView1 = LayoutInflater.from(parent.getContext())
.inflate(R.layout.feeds_adv_single_row, parent, false);
return new MyViewHolder(itemView1);
case 0:
itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.feeds_single_row, parent, false);
return new MyViewHolder(itemView);
case 2:
nativeExpressLayoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.ad_view_type, parent, false);
return new MyViewHolder(nativeExpressLayoutView);
}
return null;
}
#Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
movie = worldpopulationlist.get(holder.getAdapterPosition());
if (holder.mview == itemView1) {
holder.brandImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent x = new Intent(context, Full_Image.class);
x.putExtra("image",worldpopulationlist.get(position).getBrand_Image());
context.startActivity(x);
}
});
holder.mview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, AdsActivity.class);
intent.putExtra("adsNext", worldpopulationlist.get(position).getAdsSecond());
intent.putExtra("objId", worldpopulationlist.get(position).getObjectId());
intent.putExtra("brandImage", worldpopulationlist.get(position).getBrand_Image());
intent.putExtra("brandName", worldpopulationlist.get(position).getAuthor_Name());
intent.putExtra("link", worldpopulationlist.get(position).getLink());
intent.putExtra("mobNo", worldpopulationlist.get(position).getCall());
intent.putExtra("brandDescription", worldpopulationlist.get(position).getPages());
intent.putExtra("brandDescriptionText", worldpopulationlist.get(position).getPage_No());
intent.putExtra("contactUs", worldpopulationlist.get(position).getContactUs());
intent.putExtra("aboutUs", worldpopulationlist.get(position).getAboutUs());
context.startActivity(intent);
}
});
} else if (holder.mview == itemView) {
holder.mview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, Feeds_Second.class);
intent.putExtra("rank", worldpopulationlist.get(position).getImagesContent());
intent.putExtra("image", worldpopulationlist.get(position).getFlag());
intent.putExtra("ads", worldpopulationlist.get(position).getAds());
intent.putExtra("call", worldpopulationlist.get(position).getCall());
intent.putExtra("objectId", worldpopulationlist.get(position).getObjectId());
intent.putExtra("contactUs", worldpopulationlist.get(position).getContactUs());
intent.putExtra("aboutUs", worldpopulationlist.get(position).getAboutUs());
intent.putExtra("switch", worldpopulationlist.get(position).getSwitches());
intent.putExtra("link", worldpopulationlist.get(position).getLink());
intent.putExtra("clicks", worldpopulationlist.get(position).getClicks());
context.startActivity(intent);
}
});
}
x = movie.getAds();
if (x == 1) {
holder.brandName.setText(movie.getAuthor_Name());
holder.brandDescription.setText(movie.getPages()); // when setting brandDescription to the objectId it shows objectId ysZicAeoRU
holder.brandDescriptionText.setText(movie.getPage_No());
Picasso.with(context)
.load(worldpopulationlist.get(position).getBrand_Image())
.placeholder(R.drawable.place_holder)
.error(R.drawable.broken_image)
.into(holder.brandImage);
Picasso.with(context)
.load(worldpopulationlist.get(position).getFlag())
.placeholder(R.drawable.place_holder)
.error(R.drawable.broken_image)
.into(holder.brandMainImage);
} else if (x==0){
holder.imageContent.setText(movie.getImagesContent());
holder.userName.setText(movie.getAddress());
holder.author.setText(movie.getAuthor());
holder.authorName.setText(movie.getAuthor_Name());
holder.pages.setText(movie.getPages());
holder.pageNo.setText(String.valueOf(movie.getClicks()));
holder.userImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent y = new Intent(context, WrapImage.class);
y.putExtra("image",worldpopulationlist.get(position).getUserImage());
context.startActivity(y);
}
});
Picasso.with(context)
.load(worldpopulationlist.get(position).getUserImage())
.placeholder(R.drawable.place_holder)
.error(R.drawable.broken_image)
.into(holder.userImage);
Picasso.with(context)
.load(worldpopulationlist.get(position).getFlag())
.placeholder(R.drawable.place_holder)
.error(R.drawable.broken_image)
.into(holder.feedsImage);
} else if (x ==2){
holder.adView.loadAd(adRequest);
}
}
#Override
public int getItemCount() {
return worldpopulationlist.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView imageContent, userName, author, authorName, pages, pageNo;
TextView brandName, brandDescription, brandDescriptionText;
ImageView feedsImage, brandImage, brandMainImage, userImage;
View mview;
AdView adView;
public MyViewHolder(View v) {
super(v);
mview = v;
imageContent = (TextView) v.findViewById(R.id.recycler_text);
feedsImage = (ImageView) v.findViewById(R.id.flag);
userImage = (ImageView) v.findViewById(R.id.userImage);
userName = (TextView) v.findViewById(R.id.userName);
author = (TextView) v.findViewById(R.id.author);
authorName = (TextView) v.findViewById(R.id.author_name);
pages = (TextView) v.findViewById(R.id.pages);
pageNo = (TextView) v.findViewById(R.id.page_no);
brandName = (TextView) v.findViewById(R.id.brand_name);
brandDescription = (TextView) v.findViewById(R.id.author_brand_description);
brandDescriptionText = (TextView) v.findViewById(R.id.author_name_brand_description);
brandImage = (ImageView) v.findViewById(R.id.brand_image);
brandMainImage = (ImageView) v.findViewById(R.id.brand_main_image);
adView = (AdView)v. findViewById(R.id.adView);
}
}
}

Categories

Resources