I have in my project Android Design Library and I'm working with navigation view but I have an issue with it. From API 15 till 20 everything is working fine as suppose to work but when I tried on API 21 (5.0) and higher it's not working even it's not showing the hamburger button. And I can't find where is the problem. Does anyone faced with similar problem? I'm working in xamarin with C#. This is the code:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using Android.Support.Design.Widget;
using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using Android.Content;
using Android.Views;
using Android.Webkit;
namespace Cazin.Net
{
[Activity (Label = "Cazin.Net", Icon = "#mipmap/icon",Theme="#style/MyTheme")]
public class MainActivity : AppCompatActivity
{
static readonly string TAG = "X:" + typeof(MainActivity).Name;
List<FeedItem> feedList;
ProgressDialog progressDialog;
ProgressBar progressBar;
ListView feedListView;
LinearLayout linearHome;
LinearLayout linearSport;
LinearLayout linearMagazin;
DrawerLayout drawerLayout;
TextView textView;
TextView textViewTemp;
TextView textViewTemperature;
TextView textViewHumidty;
ImageView imageView;
ActionBarDrawerToggle drawerToggle;
public static string MTitle = "com.example.cazin_net.Title";
public static string mWriter = "com.example.cazin_net.Writer";
public static string mPubdate = "com.example.cazin_net.PubDate";
public static string Description = "com.example.cazin_net.Description";
public static string Image = "com.example.cazin_net.Image";
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
feedListView = FindViewById<ListView> (Resource.Id.feedItemlistview);
linearHome = FindViewById<LinearLayout> (Resource.Id.linearLayoutHome);
linearSport = FindViewById<LinearLayout> (Resource.Id.linearSport);
linearMagazin = FindViewById<LinearLayout> (Resource.Id.linearMagazin);
textView = FindViewById<TextView> (Resource.Id.textWeather);
imageView = FindViewById<ImageView> (Resource.Id.imageweather);
textViewTemp = FindViewById<TextView> (Resource.Id.textWeatherTemp);
textViewTemperature = FindViewById<TextView> (Resource.Id.textWeatherTemperature);
textViewHumidty = FindViewById<TextView> (Resource.Id.textWeatherHumidity);
this.progressDialog = new ProgressDialog (this);
this.progressBar = FindViewById<ProgressBar> (Resource.Id.myProgrsesbar);
progressDialog.SetMessage ("Dobavljam vijesti...");
GetItemList ();
linearHome.Pressed = true;
//setting up drawer layout
drawerLayout = FindViewById<DrawerLayout> (Resource.Id.drawer_layout);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar> (Resource.Id.toolbar);
SetSupportActionBar (toolbar);
SupportActionBar.SetDisplayHomeAsUpEnabled (true);
SupportActionBar.SetDisplayShowHomeEnabled(true);
drawerToggle = new ActionBarDrawerToggle (this, drawerLayout, toolbar,
Resource.String.open_drawer, Resource.String.close_drawer);
drawerLayout.SetDrawerListener (drawerToggle);
drawerToggle.SyncState ();
linearHome.Click += (object sender, EventArgs e) =>
{
var intent = new Intent(this, typeof(MainActivity));
Finish();
StartActivity(intent);
};
linearSport.Click += (object sender, EventArgs e) =>
{
var intent = new Intent(this, typeof(SportActivity));
StartActivity(intent);
};
linearMagazin.Click += (object sender, EventArgs e) =>
{
var intent = new Intent(this, typeof(MagazinActivity));
StartActivity(intent);
linearMagazin.Pressed = true;
};
var navView = FindViewById<NavigationView> (Resource.Id.nav_view);
navView.NavigationItemSelected += (object sender, NavigationView.NavigationItemSelectedEventArgs e) =>
{
switch (e.MenuItem.ItemId) {
case(Resource.Id.nav_cazin):
var intent = new Intent(this, typeof(CazinActivity));
StartActivity(intent);
break;
case(Resource.Id.nav_vijesti):
var vijesti = new Intent(this, typeof(VijestiActivity));
StartActivity(vijesti);
break;
case(Resource.Id.nav_izdvojeno):
var intentIzdvojeno = new Intent(this, typeof(IzdvojenoActivity));
StartActivity(intentIzdvojeno);
break;
case(Resource.Id.nav_oglasi):
var oglasi = new Intent(this, typeof(Oglasi));
StartActivity(oglasi);
break;
case(Resource.Id.nav_diskusije):
break;
case(Resource.Id.nav_video):
break;
case(Resource.Id.nav_radio):
break;
default:
break;
}
drawerLayout.CloseDrawer(navView);
};
var navViewRight = FindViewById<NavigationView> (Resource.Id.nav_viewright);
navViewRight.NavigationItemSelected += (object sender, NavigationView.NavigationItemSelectedEventArgs e) =>
{
switch (e.MenuItem.ItemId)
{
case(Resource.Id.nav_facebook):
var facebook = new Intent(this, typeof(FacebookActivity));
StartActivity(facebook);
break;
case(Resource.Id.nav_twitter):
var twitter = new Intent(this, typeof(TwitterActivity));
StartActivity(twitter);
break;
case(Resource.Id.nav_googleplus):
var googlePlus = new Intent(this, typeof(GooglePlus));
StartActivity(googlePlus);
break;
default:
break;
}
};
}
private void GetItemList()
{
this.progressDialog.Show ();
Task<List<FeedItem>> task = Task.Factory.StartNew (() => {
return FeedService.GetFeedItems ("http://www.cazin.net/vijesti/rss84234532133");
});
Task task2 = task.ContinueWith ((s) => {
try {
this.progressDialog.Dismiss ();
this.feedList = s.Result;
this.PopulateListView (this.feedList);
} catch (AggregateException ex) {
Toast.MakeText (this, ex.InnerException.Message, ToastLength.Short).Show ();
}
}, TaskScheduler.FromCurrentSynchronizationContext ());
}
void PopulateListView(List<FeedItem> list)
{
this.RunOnUiThread (() =>
{
var adapter = new FeedItemListAdapter(this, list);
feedListView.Adapter = adapter;
feedListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
{
var feedItem = adapter[e.Position];
FeedItem itemFeed = new FeedItem()
{
Title = feedItem.Title,
PubDate = feedItem.PubDate,
Description = feedItem.Description,
Writer = feedItem.Writer,
Image = feedItem.Image
};
var newsDetail = new Intent(Application.Context, typeof(FeedDetails));
newsDetail.PutExtra(MTitle, itemFeed.Title);
newsDetail.PutExtra(mWriter, itemFeed.Writer);
newsDetail.PutExtra(mPubdate, itemFeed.PubDate.ToString());
newsDetail.PutExtra(Description, itemFeed.Description);
newsDetail.PutExtra(Image, itemFeed.Image);
StartActivity(newsDetail);
};
});
}
void GetWeather()
{
progressBar.Visibility = ViewStates.Visible;
this.RunOnUiThread (async () => {
RootObject myweather = await OpenWeatherMap.GetWeather(15.94, 44.97);
textView.Text = "Lokacija: " + myweather.name.ToUpper();
textViewTemperature.Text = "Temperatura: " + (int)myweather.main.temp + "°C";
textViewTemp.Text = "Opis: " + myweather.weather[0].description;
textViewHumidty.Text = "Vlažnost: " + myweather.main.humidity.ToString() + "%";
if(myweather.weather[0].description == "clear sky")
imageView.SetImageResource(Resource.Drawable.ic_sunny);
else if(myweather.weather[0].description == "few clouds")
imageView.SetImageResource(Resource.Drawable.ic_few_cluds);
else if(myweather.weather[0].description == "overcast clouds" )
imageView.SetImageResource(Resource.Drawable.ic_scattered_clouds);
else if(myweather.weather[0].description == "scattered clouds" )
imageView.SetImageResource(Resource.Drawable.ic_scattered_clouds);
else if(myweather.weather[0].description == "broken clouds")
imageView.SetImageResource(Resource.Drawable.ic_scattered_clouds);
else if(myweather.weather[0].description == "shower rain")
imageView.SetImageResource(Resource.Drawable.ic_shower_rain);
else if(myweather.weather[0].description == "light rain")
imageView.SetImageResource(Resource.Drawable.ic_shower_rain);
else if(myweather.weather[0].description == "rain")
imageView.SetImageResource(Resource.Drawable.ic_rain);
else if(myweather.weather[0].description == "moderate rain")
imageView.SetImageResource(Resource.Drawable.ic_shower_rain);
else if(myweather.weather[0].description == "thunderstorm")
imageView.SetImageResource(Resource.Drawable.ic_rain);
else if(myweather.weather[0].description == "snow")
imageView.SetImageResource(Resource.Drawable.ic_snow);
else if(myweather.weather[0].description == "mist")
imageView.SetImageResource(Resource.Drawable.ic_mist);
progressBar.Visibility = ViewStates.Gone;
});
}
public override bool OnCreateOptionsMenu (Android.Views.IMenu menu)
{
MenuInflater.Inflate (Resource.Menu.menu, menu);
return base.OnCreateOptionsMenu (menu);
}
public override bool OnOptionsItemSelected (IMenuItem item)
{
var navViewRight = FindViewById<NavigationView> (Resource.Id.nav_viewright);
switch (item.ItemId)
{
case Resource.Id.action_help:
drawerLayout.OpenDrawer (navViewRight);
GetWeather ();
return true;
default:
break;
}
return base.OnOptionsItemSelected(item);
}
}
}
And AXML code:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout">
<ListView
android:id="#+id/feedItemlistview"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingTop="80dp"
android:dividerHeight="10dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark" />
<LinearLayout
android:orientation="horizontal"
android:id="#+id/mainLayout"
android:layout_alignParentBottom="true"
android:background="?attr/colorPrimary"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:weightSum="100">
<LinearLayout
android:orientation="vertical"
android:layout_weight="25"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/linearLayoutHome"
android:padding="0dp"
android:weightSum="100"
android:background="#drawable/Selector"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/imageView1"
android:src="#drawable/ic_home_black_24dp"
android:layout_weight="50"
android:scaleType="fitCenter"
android:adjustViewBounds="false" />
<TextView
android:text="Početna"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:textStyle="bold"
android:id="#+id/textView1"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="25"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/linearMagazin"
android:weightSum="100"
android:padding="0dp"
android:background="#drawable/Selector"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/imageView2"
android:layout_weight="50"
android:src="#drawable/ic_whatshot_black_24dp"
android:scaleType="fitCenter"
android:adjustViewBounds="false" />
<TextView
android:text="Magazin"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:textStyle="bold"
android:id="#+id/textView2"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="25"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/linearSport"
android:weightSum="100"
android:padding="0dp"
android:background="#drawable/Selector"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:id="#+id/imageView3"
android:src="#drawable/ic_directions_bike_black_24dp"
android:scaleType="fitCenter"
android:adjustViewBounds="false" />
<TextView
android:text="Sport"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:textStyle="bold"
android:id="#+id/textView3"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="25"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/linearLayout4"
android:weightSum="100"
android:padding="0dp"
android:clickable="true"
android:background="#drawable/Selector"
android:focusable="false"
android:focusableInTouchMode="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/imageView4"
android:layout_weight="50"
android:src="#drawable/ic_photo_library_black_24dp"
android:scaleType="fitCenter"
android:adjustViewBounds="false" />
<TextView
android:text="Galerija"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:textStyle="bold"
android:id="#+id/textView4"
android:gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="#+id/nav_view"
app:theme="#style/NavigationDrawerStyle"
app:menu="#menu/navigationmenu"
android:background="#android:color/white"
app:headerLayout="#layout/header" />
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:weightSum="100"
android:layout_gravity="right"
android:background="#android:color/white"
android:id="#+id/nav_viewright"
app:theme="#style/NavigationDrawerStyle"
app:menu="#menu/navigationmenuright">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="60"
android:weightSum="100"
android:orientation="vertical"
android:background="#android:color/holo_blue_bright">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/myProgrsesbar"
android:progressDrawable="#drawable/circular_progress"
android:layout_gravity="center" />
<ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="fitCenter"
android:weightSum="60"
android:id="#+id/imageweather" />
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:text="Weather"
android:weightSum="40"
android:textStyle="bold"
android:fontFamily="sans-serif"
android:textColor="#android:color/white"
android:textSize="18dp"
android:id="#+id/textWeather"
android:layout_marginTop="30dp" />
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:text="Weather"
android:weightSum="40"
android:textStyle="bold"
android:fontFamily="sans-serif"
android:textColor="#android:color/white"
android:textSize="18dp"
android:id="#+id/textWeatherTemperature"
android:layout_marginTop="4dp" />
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="Weather"
android:gravity="center"
android:weightSum="40"
android:textStyle="bold"
android:fontFamily="sans-serif"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="18dp"
android:id="#+id/textWeatherTemp"
android:layout_marginTop="4dp" />
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:text="Weather"
android:textStyle="bold"
android:weightSum="40"
android:fontFamily="sans-serif"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="18dp"
android:id="#+id/textWeatherHumidity"
android:layout_marginTop="4dp" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
If someone face in future with similar problem this was solution for my problem. As I guessed problem wasn't in code. I added design library via components but that is not the latest version and you will face with errors in android lollipop or higher so add it via NuGet Packages or make an update and you will get the latest version.
Related
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>
list.ItemClick+= not working. How I can perform item click on popup window custom listview? In simple listview the itemclick event works, but in the popup window the event is not fired. I need to get the listview item value.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="500dp"
android:gravity="center"
android:descendantFocusability="blocksDescendants"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
android:weightSum="100">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_weight="10"
android:layout_height="40dp">
<TextView
android:text="Vælg din afdeling"
android:textSize="20sp"
android:textColor="#FF222222"
android:paddingLeft="30dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/textView1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="50">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView1" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="35dp">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="#+id/btnAddExpense"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:textColor="#61222222"
android:background="#null"
android:text="Annuller"
android:layout_marginLeft="20dp"
android:layout_gravity="right"
android:layout_marginRight="15dp" />
<Button
android:id="#+id/btnok"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:textColor="#FFF62F5E"
android:text="Gem"
android:background="#null"
android:layout_marginLeft="1dp"
android:layout_gravity="right"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
In this function, I set item click event on listview but it is not working. How can I perform itemclick?
private void DepartmentPicker_Click(object sender, EventArgs e)
{
ButtonNext.Visibility = ViewStates.Invisible;
GetListView.Adapter = new DepartmentListAdapter(this, departments);
bool focusable = true;
int width = 350;// LinearLayout.LayoutParams.WrapContent;
int height = 450;//LinearLayout.LayoutParams.WrapContent;
_view.FindViewById<Button>(Resource.Id.btnok).SetOnClickListener(this);
var list= _view.FindViewById<ListView>(Resource.Id.listView1);
popupWindow = new PopupWindow(_view, width, height, focusable);
popupWindow.ContentView = _view;
popupWindow.ShowAtLocation(_view, GravityFlags.CenterVertical, 0, 0);
popupWindow.Focusable = true;
popupWindow.Touchable = true;
//listView.ChoiceMode = ChoiceMode.Single;
}
I wrote a demo about it, this is running GIF.
There is my code of MainActivity.cs
public class MainActivity : AppCompatActivity
{
List<News> data;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
Button button1 = FindViewById<Button>(Resource.Id.button1);
button1.Click += (o, e) =>
{
var popup = OnClick();
popup.ShowAsDropDown((View)o, 0, 0);
};
data = new List<News>() {
new News ("aaaaaaaa",1200),
new News ("bbbbbbbbb",560),
new News ("ccccccccc",158200),
new News ("ddddddddd",900),
};
// adapter = new NewsAdapter(data, this);
}
private PopupWindow OnClick()
{
PopupWindow _popupWindow = new PopupWindow(this);
LayoutInflater inflater= (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
View popup=inflater.Inflate(Resource.Layout.window_popup_content,null);
ListView listView1 = popup.FindViewById<ListView>(Resource.Id.listView1);
NewsAdapter adapter = new NewsAdapter(data, this);
listView1.Adapter = adapter;
listView1.ItemClick += (sender, args) =>
{
Toast.MakeText(this, data[args.Position].Title + "", ToastLength.Short).Show();
_popupWindow.Dismiss();
};
_popupWindow.Width = ViewGroup.LayoutParams.WrapContent;
_popupWindow.Height = ViewGroup.LayoutParams.WrapContent;
_popupWindow.ContentView = popup;
return _popupWindow;
}
}
There is adapter of listview.
public class NewsAdapter : BaseAdapter
{
private List<News> data;
private Context context;
public override int Count
{
get
{
return data.Count;
}
}
public NewsAdapter(List<News> data, Context context)
{
this.data = data;
this.context = context;
}
public override Java.Lang.Object GetItem(int position)
{
return null;
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
convertView = LayoutInflater.From(context).Inflate(Resource.Layout.lv_test, parent, false);
TextView title = convertView.FindViewById<TextView>(Resource.Id.tv_title);
TextView pv = convertView.FindViewById<TextView>(Resource.Id.tv_pv);
pv.Text = data[position].Pv.ToString();
title.Text = data[position].Title;
return convertView;
}
xaml of ListviewItem
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<LinearLayout
android:id="#+id/layout_content"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="#+id/tv_title"
android:layout_height="20dp"
android:layout_width="0dp"
android:layout_weight="5"
android:textColor="#000000"
android:text="aaaaaaaaa"
android:textSize="16dp" />
<TextView
android:id="#+id/tv_pv"
android:layout_height="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:textColor="#808080"
android:textSize="10dp"
android:text="19665"
android:gravity="right|center_vertical" />
</LinearLayout>
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#dedede" />
</LinearLayout>
There is my demo. you could refer to it.
https://github.com/851265601/ListviewPopUpWindowDemo
I m new to NavigationDrawer, the code below is working.
But how to get the button inside the homeLayout.axml which is inflated as indicated in HomeFragment.cs after the below code.
ft.Add(Resource.Id.HomeFrameLayout, new HomeFragment());
ft.Commit();
1) I need to add eventHandler to this btn : btnProducts in homeLayout.axml
- where to add below code
what I need to add to setup code to get the btnProducts and add event for this button??
SetContentView (Resource.Layout.????);
Btn = FindViewById<Button>(Resource.Id.BtnGM);
Btn.Click += Btn_Click1;
--- UI:
Main Layout File
<?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="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:fitsSystemWindows="true">
<android.support.v4.widget.DrawerLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/drawer_layout">
<LinearLayout
android:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="#layout/app_bar" />
<FrameLayout
android:id="#+id/HomeFrameLayout"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navmenu"
app:headerLayout="#layout/headerdrawerlayout" /> </android.support.v4.widget.DrawerLayout>
</LinearLayout>
-- Code for main UI
public class NaviDrawerActivity : AppCompatActivity
{
private SupportToolbar toolbar;
DrawerLayout drawerLayout;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.NaviDrawer);
drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
//--- Init toolbar
toolbar = FindViewById<SupportToolbar>(Resource.Id.app_bar);
SetSupportActionBar(toolbar);
SupportActionBar.SetTitle(Resource.String.app_name);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
SupportActionBar.SetDisplayShowHomeEnabled(true);
//--- Attach item selected handler to navigation view
var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;
//-- Create ActionBarDrawerToggle button and add it to the toolbar
var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer);
drawerLayout.SetDrawerListener(drawerToggle);
drawerToggle.SyncState();
//--load default home screen
var ft = FragmentManager.BeginTransaction();
ft.AddToBackStack(null);
ft.Add(Resource.Id.HomeFrameLayout, new HomeFragment());
ft.Commit();
}
//---define custom title text
protected override void OnResume()
{
SupportActionBar.SetTitle(Resource.String.app_name);
base.OnResume();
}
-------------HomeFragment.cs
class HomeFragment: Fragment
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.Inflate(Resource.Layout.homeLayout, container, false);
return view;
}
}
----------homeLayout.axml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#ffffff"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff46a2fd"
android:text="Home"
android:textSize="22dp"
android:textStyle="bold"
android:typeface="sans"
android:gravity="center"
android:layout_gravity="center"
android:layout_centerInParent="true" />
<Button
android:id="#+id/btnProducts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_marginTop="3dp"
android:background="#307FC1"
android:text="merchant"
android:layout_alignParentBottom="true"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
in your HomeFragment.cs in the OnCreateView method add the following (between the declaration of view and the return statment):
var btnProducts = view.FindViewById<Button>(Resource.Id.btnProducts);
btnProducts.Click += btnProducts_Click;
Then add the method for your click event (somewhere in your HomeFragment class):
public void btnProducts_Click(object sender, EventArgs e)
{
// Action you want to take upon button click
}
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);
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.