MvvmCross Android binding EditText in release mode - xamarin

I have a problem with binding EditText on Android platform.
Today I update in my project MvvmCross framework from 6.2.X to 6.3.1 (+ update others NuGets) and changed TargetSdk and CompileSdk from Android 8.1 to 9.0 and now when I have Release mode and linking set to "Sdk Assemblies" Only my app crash on View where I have binding EditText. In debug where I have checked "Use Shared Runtime" and set linking to "None" there is no problem it works.
I have Include TextView in LinkerPleaseInclude:
public void Include(TextView text)
{
text.AfterTextChanged += (sender, args) => text.Text = $"{text.Text}";
text.Hint = $"{text.Hint}";
}
it throws this exception: https://pastebin.com/EmkuL7hM
Layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:paddingTop="50dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundColor">
<LinearLayout
android:layout_margin="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="#+id/logo"
android:layout_width="200dp"
android:layout_height="100dp"
android:src="#drawable/ic_logo_red"
android:scaleType="fitCenter" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="Email"
local:MvxLang="Text Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primaryColor"
android:textStyle="bold"
android:textSize="#dimen/text_medium" />
<EditText
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="40dp"
local:MvxBind="Text LoginName"
android:singleLine="true"
android:inputType="textEmailAddress"
android:background="#color/white"
android:cursorVisible="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColorHint="#color/primaryTextColor"
android:textColor="#color/primaryTextColor" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="Password"
local:MvxLang="Text Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primaryColor"
android:textStyle="bold"
android:textSize="#dimen/text_medium" />
<EditText
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="40dp"
local:MvxBind="Text Password"
android:singleLine="true"
android:inputType="textPassword"
android:background="#color/white"
android:cursorVisible="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColorHint="#color/primaryTextColor"
android:textColor="#color/primaryTextColor" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:gravity="center"
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/text_large"
local:MvxLang="Text Login"
local:MvxBind="Click LoginCommand"
android:padding="10dp"
android:background="#drawable/button_round_primary"
android:textColor="#color/white"
android:text="Login"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</ScrollView>
ViewModel:
public class LoginViewModel : MvxViewModel
{
private readonly IMvxNavigationService _navigationService;
private readonly IInfoMessageReporter _infoMessageReporter;
private readonly ISessionInfo _session;
private readonly ILoginService _loginService;
private readonly IDataService _dataService;
public LoginViewModel()
{
_navigationService = Mvx.IoCProvider.Resolve<IMvxNavigationService>();
_infoMessageReporter = Mvx.IoCProvider.Resolve<IInfoMessageReporter>();
_session = Mvx.IoCProvider.Resolve<ISessionInfo>();
_loginService = Mvx.IoCProvider.Resolve<ILoginService>();
_dataService = Mvx.IoCProvider.Resolve<IDataService>();
RememberLogin = true;
}
public IMvxLanguageBinder TextSource => new MvxLanguageBinder(Constants.LocalizationNamespace, GetType().Name);
public override async Task Initialize()
{
await InitializePermissionsAsync();
}
private async Task InitializePermissionsAsync()
{
// some stuff...
}
private string _password;
public string Password
{
get => _password;
set
{
_password = value;
RaisePropertyChanged(() => Password);
}
}
private string _loginName;
public string LoginName
{
get => _loginName;
set
{
_loginName = value;
RaisePropertyChanged(() => LoginName);
}
}
private MvxAsyncCommand _loginCommand;
public IMvxAsyncCommand LoginCommand
{
get
{
_loginCommand = _loginCommand ?? new MvxAsyncCommand(async () => await ExecuteLoginAsync());
return _loginCommand;
}
}
private async Task ExecuteLoginAsync()
{
// some stuff....
}
}

I believe the issue you are experiencing is a current bug in Xamarin's latest build (around Xamarin Android 9.4). This issue can be tracked here on GitHub.
The suggested workaround
In case any other users come across this issue when using
Xamarin.Android 9.4, a possible workaround is to use a custom linker
configuration to preserve the missing types. To do that, add a new
linker.xml file to the project, set the Build Action to
LinkDescription, and add the XML lines to preserve the missing types.
For example, for the ITextWatcherInvoker error, add the following
lines to the file:
<linker>
<assembly fullname="Mono.Android">
<type fullname="Android.Text.ITextWatcherInvoker" preserve="all" />
</assembly>
</linker>

Related

RecyclerView OnclickListener in CardView

I have a list with recyclerView in which the CardView is visualized through an adapter and within the CardView I have 8 textView.
Up to that point everything is perfect, the list is displayed well.But when implementing the onClick to the cardView I have the following problem,
that the cardViews are only clickable in the background below the TextView elements, it is as if they cover the clickleable zone
ArrayList<Maquina> maquinasList;
maquinasList=new ArrayList<>();
listaMaquinas= (RecyclerView) findViewById(R.id.lista_de_maquinas);
listaMaquinas.setLayoutManager(new LinearLayoutManager(this));
maquinasAdapter adapter= new maquinasAdapter(maquinasList);
adapter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Maquina user=maquinasList.get(listaMaquinas.getChildAdapterPosition(v));
Intent intent=new Intent(ListaMaquinas.this,RegistrarMaquina.class);
Bundle bundle=new Bundle();
bundle.putSerializable("maquina",user);
intent.putExtras(bundle);
startActivity(intent);
}
});
listaMaquinas.setAdapter(adapter);
public class maquinaAdapter extends RecyclerView.Adapter<maquinaAdapter.MaquinaViewHolder> {
private ArrayList<Maquina> listaMaquinas;
private OnItemClickListener mListener;
public interface OnItemClickListener {
void onItemClick(int position);
}
public void setOnClickListener(OnItemClickListener listener){
mListener = listener;
}
public static class MaquinaViewHolder extends RecyclerView.ViewHolder{
public TextView tipo;
public TextView marca;
public TextView modelo;
public TextView serie;
public MaquinaViewHolder(View itemView,final OnItemClickListener listener){
super(itemView);
tipo= itemView.findViewById(R.id.tipo);
marca= itemView.findViewById(R.id.marca);
modelo= itemView.findViewById(R.id.modelo);
serie= itemView.findViewById(R.id.serie);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (listener!=null){
int position=getAdapterPosition();
if (position!=RecyclerView.NO_POSITION){
listener.onItemClick(position);
}
}
}
});
}
}
public maquinaAdapter(ArrayList<Maquina> listaMaquina){
listaMaquinas = listaMaquina;
}
#Override
public MaquinaViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.lista_maquinas,parent,false);
return new MaquinaViewHolder(v,mListener);
}
#Override
public void onBindViewHolder(MaquinaViewHolder holder,int position){
Maquina currentItem = listaMaquinas.get(position);
holder.tipo.setText(currentItem.getTipo());
holder.marca.setText(currentItem.getMarca());
holder.modelo.setText(currentItem.getModelo());
holder.serie.setText(currentItem.getSerie());
}
#Override
public int getItemCount(){
return listaMaquinas.size();
}
}
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="#+id/card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/cardview"
android:backgroundTintMode="multiply"
android:elevation="20dp"
card_view:cardBackgroundColor="#color/colorAccent"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="24dp"
card_view:cardMaxElevation="20dp"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal">
<LinearLayout
android:layout_width="93dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/btnbordes"
android:text="Tipo"
android:textAlignment="center"
android:textColor="#3dffb8"
android:textSize="14sp" />
<TextView
android:id="#+id/t2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/btnbordes"
android:text="Marca"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp" />
<TextView
android:id="#+id/t3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/btnbordes"
android:text="Modelo"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp" />
<TextView
android:id="#+id/t4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:background="#drawable/btnbordes"
android:text="Serie"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="227dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tipo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/text"
android:inputType="textMultiLine"
android:isScrollContainer="true"
android:maxLines="4"
android:textAlignment="center"
android:textColor="#3dffb8"
android:textSize="14sp" />
<TextView
android:id="#+id/marca"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/text"
android:inputType="textMultiLine"
android:isScrollContainer="true"
android:maxLines="4"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp" />
<TextView
android:id="#+id/modelo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/text"
android:inputType="textMultiLine"
android:isScrollContainer="true"
android:maxLines="4"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp" />
<TextView
android:id="#+id/serie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:background="#drawable/text"
android:inputType="textMultiLine"
android:isScrollContainer="true"
android:maxLines="4"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
This is the code of the cardViews that are displayed in the list. I have already reviewed the adapter and the other classes and I think the problem is in the CardView Configuration.
Thank you very much in advance.
this is sample adapter of RecyclerView.Adapter
public class Adapter extends RecyclerView.Adapter<Adapter.MyViewHolder> {
private ListItemClickListener mOnClickListener;
public interface ListItemClickListener{
void onListItemClick(View view, int postion);
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView title;
public CardView cardView;
public MyViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.tvTitle);
cardView=(CardView)view.findViewById(R.id.card_view);
title.setOnClickListener(this);
cardView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
mOnClickListener.onListItemClick(v, getAdapterPosition());
}
}
public void setClickListener(ListItemClickListener itemClickListener) {
this.mOnClickListener = itemClickListener;
}
Now implement Adapter.ListItemClickListener on your activity class and set the setClickListener of your adapter
Adapter.setClickListener(this);
//the intent where to go inside the implemented method

(MapFragment)FragmentManager.FindFragmentById(Resource.Id.map) retuns null always

I am trying to import google map in to my xamarin.android application. I set the key and written code as following `
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Maps);
SetUpMap();
FindViewElements();
}
private void SetUpMap()
{
if (mMap == null)
{
var _mapFragment = FragmentManager.FindFragmentByTag("maptag") as MapFragment;//null
var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);//null
// var mapFragment = FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map);//Here are also null
// var _mapFragment = SupportFragmentManager.FindFragmentById(Resource.Id.map) as SupportMapFragment; /null
}
}
protected override async void FindViewElements()
{
_mapsModel = new MapsModel
{
MapsFragment = FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map),
MapTypeSpinner = FindViewById<Spinner>(Resource.Id.spinner),
Toolbar = FindViewById<Toolbar>(Resource.Id.mapToolbar),
};
SetSupportActionBar(_mapsModel.Toolbar);
SupportActionBar.Title = "Maps";
SupportActionBar.SetHomeButtonEnabled(true);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
_mapsModel.MapsFragment.GetMapAsync(this);
_mapsModel.MapTypeSpinner.ItemSelected += MapTypeSpinner_ItemSelected;
}
I have axml as following
<?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:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/header">
<include
android:id="#+id/mapToolbar"
layout="#layout/toolbar" />
</RelativeLayout>
<Spinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/maptype_arrays" />
<fragment
android.id="#+id/map"
android:tag="maptag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>
I tried every possible way which I found like replacing Fragment to suppportFragment but nothing got helped. Can any one please suggest me to achieve this.
Thanks in advance
I try your axml, and I get the result as your, so I suggest you can add fragment in FrameLayout, so you can get this fragment by Id. Like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/zoomInButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Zoom In" />
<Button
android:id="#+id/zoomOutButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Zoom Out" />
<Button
android:id="#+id/animateButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Animate to Location" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</FrameLayout>
var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
You can also take a look the MSDN document about importing Google map in your project:
https://learn.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/maps-api

Xamarin - RecyclerView with PagerSlidingTabStrip - System.NullReferenceException in SetLayoutManager()

I try to use a RecyclerView in a SlideMenu.
I use this example for my SlideMenu : https://github.com/jamesmontemagno/PagerSlidingTabStrip-for-Xamarin.Android
And now, I add RecyclerView with SlideMenu. I need two menu : "menu" and "product", so I use two xml file for my fragment : menu.xml for "menu" and menu_recyclerView.xml for "product".
This is my code :
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true" >
<include
android:id="#+id/top_menu"
layout="#layout/top_menu"/>
<com.refractored.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:pstsShouldExpand="true"
android:background="#color/Blue"
app:pstsDividerWidth="1dp"
app:pstsDividerPadding="12dp"
app:pstsDividerColor="#50FFFFFF"
android:textColor="#color/Green"
app:pstsTextColorSelected="#color/White"
app:pstsIndicatorColor="#color/Red"
app:pstsUnderlineColor="#color/White"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
menu_recyclerView.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/menu_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</LinearLayout>
row_recyclerView is a pattern for my items
row_recyclerView.xml
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:orientation="vertical">
<refractored.controls.CircleImageView
android:id="#+id/imageView"
app:civ_border_width="2dp"
app:civ_border_color="#000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="88"
android:orientation="vertical"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="7dp"
android:paddingBottom="7dp">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtName"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="18sp" />
<TextView
android:text="Brand"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtBrand"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="14sp"
android:singleLine="true" />
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtDescription"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
-
public class MainActivity : BaseActivity
{
protected override int LayoutResource
{
get
{
return Resource.Layout.Main;
}
}
private Android.Widget.Toolbar _topMenu;
private Adapter _adapter;
private ViewPager _pager;
private PagerSlidingTabStrip _tabs;
private RecyclerView _recyclerView;
private LayoutManager _layoutManager;
public string _tag = "MainActivity";
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
_recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
_layoutManager = new LayoutManager(this, _recyclerView);
_layoutManager.addItem("one", "two", "three");
_layoutManager.addItem("one", "two", "three");
_layoutManager.createLayoutManager();
_adapter = new Adapter(SupportFragmentManager);
_pager = FindViewById<ViewPager>(Resource.Id.pager);
_tabs = FindViewById<PagerSlidingTabStrip>(Resource.Id.tabs);
_pager.Adapter = _adapter;
_tabs.SetViewPager(_pager);
_topMenu = FindViewById<Android.Widget.Toolbar>(Resource.Id.top_menu);
SetActionBar(_topMenu);
}
-
class LayoutManager
{
public RecyclerView _mRecyclerView;
public RecyclerView.LayoutManager _mLayoutManager;
public RecyclerView.Adapter _mAdapter;
public ItemList<Item> _mItems;
public Activity _main;
public LayoutManager(Activity main, RecyclerView recyclerView)
{
_main = main;
_mRecyclerView = recyclerView;
_mItems = new ItemList<Item>();
}
public void createLayoutManager()
{
_mLayoutManager = new LinearLayoutManager(_main);
_mRecyclerView.SetLayoutManager(_mLayoutManager);
_mAdapter = new RecyclerAdapter(_mItems, _mRecyclerView);
_mItems.Adapter = _mAdapter;
_mRecyclerView.SetAdapter(_mAdapter);
}
public void addItem(string name, string brand, string description)
{
_mItems.Add(new Item()
{
Img = Resource.Drawable.Icon,
Name = name,
Brand = brand,
Desciption = description
});
}
}
And in this line (in my LayoutManager.cs):
_mRecyclerView.SetLayoutManager(_mLayoutManager);
I have This error :
System.NullReferenceException: Object reference not set to an instance of an object.
I do not understand what is the value of the probleme ?
I forget any thing ?
I am completely lost ?
Please.. help !
Thanks you,
Romain
According to your code: public class MainActivity : BaseActivity and
protected override int LayoutResource
{
get
{
return Resource.Layout.Main;
}
}
I guess that your BaseActivity is the same as BaseActivity.cs of PagerSlidingTabStrip sample.
Then you actually here set your Main.xml as the content view of your MainActivity, and in this Main.xml, there is no RecyclerView with the id recyclerView, it is in your menu_recyclerView.xml. Although you can find the id recyclerView when you coding, but it is not present on the content view.
So in your MainActivity, when you try to find it using _recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);, this _recyclerView here should be null when you run your code. Then of course when you call _layoutManager = new LayoutManager(this, _recyclerView);, you pass a null to this LayoutManager. You can insert a break point on this line to check if it is a null:
_recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
To solve your issue, I think you may need to redesign your layout or your frame.
Thanks for your answer !
Yes my BaseActivity il the same as BaseActivity.cs of PagerSlidingTabStrip sample.
I follow your advice, and yes I have a probleme with my architecture.
I learn how it works the RecyclerView, and I add this :
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true" >
<include
android:id="#+id/top_menu"
layout="#layout/top_menu"/>
<com.refractored.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:pstsShouldExpand="true"
android:background="#color/Blue"
app:pstsDividerWidth="1dp"
app:pstsDividerPadding="12dp"
app:pstsDividerColor="#50FFFFFF"
android:textColor="#color/Green"
app:pstsTextColorSelected="#color/White"
app:pstsIndicatorColor="#color/Red"
app:pstsUnderlineColor="#color/White"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include
layout="#layout/recyclerView" />
</LinearLayout>
menu_recyclerView.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:orientation="vertical">
<refractored.controls.CircleImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:civ_border_width="2dp"
app:civ_border_color="#000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="88"
android:orientation="vertical"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="7dp"
android:paddingBottom="7dp">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtName"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="18sp" />
<TextView
android:text="Brand"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtBrand"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="14sp"
android:singleLine="true" />
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtDescription"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
I add the new xml file : recyclerView.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
Now I call recyclerView.xml in my Main.xml. recyclerView.xml contain CardView, and he wrap RecyclerView.
I should put my RecyclerView in a only CardView or I should to wrap my menu_recyclerView.xml with cardView ?
I want to create a menu like this :
I have a result, but now I think I have a probleme with my menu_recyclerView.xml because I don't have a list, juste "name, brand, description". screenshot :
I search for this, and is a another subject...
I think the good keyword for this probleme is : RecyclerView, CardView
for finish this is my other sources :
https://www.binpress.com/tutorial/android-l-recyclerview-and-cardview-tutorial/156
How to add listView inside cardView android?
How to implement RecyclerView with CardView rows in a Fragment with TabLayout
Thanks a lot,

Unable to convert instance of type 'Android.Widget.EditText' to type 'Android.Widget.Button'

I try to execute the following tutorial :
namespace App1
{
[Activity(Label = "App1", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get the latitude/longitude EditBox and button resources:
EditText latitude = FindViewById<EditText>(Resource.Id.latText);
EditText longitude = FindViewById<EditText>(Resource.Id.longText);
Button button = FindViewById<Button>(Resource.Id.getWeatherButton);
// When the user clicks the button ...
button.Click += async (sender, e) => {
// Get the latitude and longitude entered by the user and create a query.
string url = "http://api.geonames.org/findNearByWeatherJSON?lat=" +
latitude.Text +
"&lng=" +
longitude.Text +
"&username=demo";
// Fetch the weather information asynchronously,
// parse the results, then update the screen:
JsonValue json = await FetchWeatherAsync(url);
// ParseAndDisplay (json);
};
}
// Gets weather data from the passed URL.
private async Task<JsonValue> FetchWeatherAsync(string url)
{
// Create an HTTP web request using the URL:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.ContentType = "application/json";
request.Method = "GET";
// Send the request to the server and wait for the response:
using (WebResponse response = await request.GetResponseAsync())
{
// Get a stream representation of the HTTP web response:
using (Stream stream = response.GetResponseStream())
{
// Use this stream to build a JSON document object:
JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());
// Return the JSON document:
return jsonDoc;
}
}
}
}
}
but when I debug it a pop-up open with the following message : "System.InvalidCastException: Unable to convert instance of type 'Android.Widget.EditText' to type 'Android.Widget.Button'."
I add the main layout code because Xamarin shows me the mistake on Edit Text :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:id="#+id/latSection">
<TextView
android:text="Enter Latitude:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="140dp"
android:layout_height="40dp"
android:gravity="right"
android:id="#+id/latLabel" />
<EditText
android:text="47.7"
android:layout_width="150dp"
android:layout_height="50dp"
android:id="#+id/latText"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:id="#+id/longSection">
<TextView
android:text="Enter Longitude:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="140dp"
android:layout_height="40dp"
android:gravity="right"
android:id="#+id/longLabel" />
<EditText
android:text="-122.5"
android:layout_width="150dp"
android:layout_height="50dp"
android:id="#+id/longText"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_marginTop="28dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:id="#+id/getSection">
<Button
android:id="#+id/getWeatherButton"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Get Weather" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/locSection">
<TextView
android:text="Location:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="120dp"
android:layout_height="30dp"
android:gravity="left"
android:id="#+id/locLabel" />
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:gravity="left"
android:id="#+id/locationText" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tempSection">
<TextView
android:text="Temperature:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="120dp"
android:layout_height="30dp"
android:gravity="left"
android:id="#+id/tempLabel" />
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:gravity="left"
android:id="#+id/tempText" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/humidSection">
<TextView
android:text="Humidity:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="120dp"
android:layout_height="30dp"
android:gravity="left"
android:id="#+id/humidLabel" />
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:gravity="left"
android:id="#+id/humidText" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/condSection">
<TextView
android:text="Conditions:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="120dp"
android:layout_height="30dp"
android:gravity="left"
android:id="#+id/condLabel" />
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:gravity="left"
android:id="#+id/condText" />
</LinearLayout>
Thanks for your help.
----EDIT-----
I finish to resolve my problem .
namespace App1
{
[Activity(Label = "App1", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
private Button button;
private EditText latitude;
private EditText longitude;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get the latitude/longitude EditBox and button resources:
latitude = FindViewById<EditText>(Resource.Id.latText);
longitude = FindViewById<EditText>(Resource.Id.longText);
button = FindViewById<Button>(Resource.Id.getWeatherButton);
Replace <Edittext> with <TextView>
latitude = FindViewById<TextView>(Resource.Id.latText);
longitude = FindViewById<TextView>(Resource.Id.longText);

Horizontal RecyclerViews inside vertical RecyclerView scrolling jerks

I am using a layout in which I used multiple RecyclerViews (Horizontal) as a item view of RecyclerView. The problem is that the vertical scrolling is not as smooth as I am expecting.There are some jerks in while scrolling vertically(Parent RecyclerView).
How to remove these vertical scrolling jerks ? I used to set adapters to horizontal RecyclerViews in OnBindViewHolder() method of Parent RecyclerView.
I have solved the problem.
Scrolling performance is much better in this case.
Do not set adapters to horizontal RecyclerViews in OnBindViewHolder() method of Parent RecyclerView.
Instead of it set it at very first time when the view is created via onCreateViewHolder() of RecyclerView with empty or null dataList.
Just replace the new secondary data list with previous null list at onBindViewHolder() and call notifydataSetChanged() to HorizontalAdapetr.
This is much better than setAdapter() in onBindViewHolder().
You can try this way
main activity
public void initialize(List<List<ResponseObject>> responseObjectList) {
RecyclerView upperRecyclerView = (RecyclerView) this.findViewById(R.id.main_layout);
upperRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
VerticalAdapter adapter = new VerticalAdapter(this, responseObjectLists);
upperRecyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
Vertical recycled view adapter
public class VerticalAdapter extends RecyclerView.Adapter<VerticalAdapter.Holder> {
final private SearchActivity activity;
List<List<ResponseObject>> list;
public VerticalAdapter(SearchActivity activity, List<List<ResponseObject>> lists) {
this.list = lists;
this.activity = activity;
}
public Holder onCreateViewHolder(ViewGroup parent,int viewType) {
View itemLayoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.vertical_layout, null);
return new Holder(itemLayoutView);
}
public void onBindViewHolder(Holder viewHolder, int position) {
List<ResponseObject> objectList = list.get(position);
viewHolder.packageTitle.setText(objectList.get(0).getTag());
ImageAdapter imageAdapter = new ImageAdapter(activity, objectList);
viewHolder.horizontalRecyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false));
viewHolder.horizontalRecyclerView.setAdapter(imageAdapter);
viewHolder.horizontalRecyclerView.setNestedScrollingEnabled(false);
imageAdapter.notifyDataSetChanged();
}
public final static class Holder extends RecyclerView.ViewHolder {
protected TextView packageTitle;
protected RecyclerView horizontalRecyclerView;
public Holder(View view) {
super(view);
this.packageTitle = (TextView) view.findViewById(R.id.recycleViewTitle);
this.horizontalRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
this.horizontalRecyclerView.setLayoutManager(new LinearLayoutManager(this.horizontalRecyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
this.horizontalRecyclerView.setNestedScrollingEnabled(false);
horizontalRecyclerView.setAdapter(null);
}
}
public int getItemCount() {
return ListUtil.isEmpty(list) ? 0 : list.size();
}
}
Horizontal recycleview adapter
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
private List<ResponseObject> mainPageResponseList;
private SearchActivity activity;
public ImageAdapter(SearchActivity activity, List mainPageResponseList) {
this.mainPageResponseList = mainPageResponseList;
this.activity = activity;
}
public ImageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLayoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.horizontal_layout_view, null);
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
public void onBindViewHolder(ViewHolder viewHolder, int position) {
ResponseObject object = mainPageResponseList.get(position);
Util.setImageUsingGlide(object.getImage(), viewHolder.imageView);
viewHolder.packageName.setText(object.getDestination());
viewHolder.packagePrice.setText(object.getPrice() + "");
viewHolder.imageView.setOnClickListener(null);
}
public final static class ViewHolder extends RecyclerView.ViewHolder {
protected ImageView imageView;
protected TextView packageName;
protected TextView packagePrice;
public ViewHolder(View view) {
super(view);
this.imageView = (ImageView) view.findViewById(R.id.packageImage);
this.packageName = (TextView) view.findViewById(R.id.packageName);
this.packagePrice = (TextView) view.findViewById(R.id.packagePrice);
}
}
public int getItemCount() {
return ListUtil.isEmpty(mainPageResponseList) ? 0 : mainPageResponseList.size();
}
}
main_layout.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:background="#color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
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="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ivHolidayMainImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<ImageView
android:id="#+id/ivHotelImage"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignTop="#id/ivHolidayMainImage"
android:background="#drawable/gradient_from_up_hotel_image" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="250dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
<TextView
android:id="#+id/mainPackageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Popular Pick"
android:textColor="#color/white"
android:textSize="12dp" />
<TextView
android:id="#+id/mainPackageName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mainPackageTitle"
android:text="Andaman Islands"
android:textColor="#color/white"
android:textSize="18dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="10dp">
<TextView
android:id="#+id/mainPackagePrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="25000"
android:textColor="#color/white"
android:textSize="18dp" />
<TextView
android:id="#+id/journeyType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mainPackagePrice"
android:text="Popular Pick"
android:textColor="#color/white"
android:textSize="12dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="-100dp"
android:background="#drawable/gradient_from_down_hotel_image" />
</app.viaindia.views.ViaLinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#drawable/ic_sms_black"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end" />
vertical_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<TextView
android:id="#+id/recycleViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Beaches"
android:textColor="#color/black_light"
android:textSize="20dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_gravity="center"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
holizontal_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:viaCustom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/packageImage"
android:layout_width="wrap_content"
android:layout_height="230dp"
android:scaleType="fitXY"
android:src="#drawable/cheese_1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="160dp">
<TextView
android:id="#+id/tvNightAndDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="3 Night/4 days"
android:textColor="#color/white" />
</RelativeLayout>
</RelativeLayout>
Try to notifydatasetChanged() in onbindViewHolder() not setAdapter(). SetAdapter() is more time consuming than notifying datset change.

Resources