Xamarin.Forms. Redraw ListView items





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a problem only on Android. My items in Listview don't update sometimes. I open a view and I see item without text or space (screen 1-2). I scroll down and then scroll up. Item redrawes and text is shown or space is removed (screen 3)
How can I fix it?
Below are the pictures:




  1. https://i.stack.imgur.com/iv0RC.png


  2. https://i.stack.imgur.com/Kdjs8.png


  3. https://i.stack.imgur.com/FJ4JJ.png



My List:



    <Grid BackgroundColor="{Binding ListViewCustomizer.DefaultBackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<recycle:RecycleListView ItemsSource="{Binding NewsFeedItems}"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
ShowAdvertisementEvery="10"
ItemSelected="HandleItemSelected" RefreshCommand="{Binding RefreshCommand}"
RowSpacing="0" ItemMargin="0"
LoadMoreCommand="{Binding LoadMoreCommand}"
IsLoadMoreEnabled="True"
IsLoadingMore="{Binding IsOldestLoading}"
IsRefreshing="{Binding IsRefreshing}"
IsPullToRefreshEnabled="True">
<recycle:RecycleListView.IsAdvertisementEnabled>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>
false
</OnPlatform.iOS>
<OnPlatform.Android>
true
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.IsAdvertisementEnabled>
<recycle:RecycleListView.ItemHeight>
<extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
</recycle:RecycleListView.ItemHeight>
<recycle:RecycleListView.Padding>
<OnPlatform x:TypeArguments="Thickness">
<OnPlatform.iOS>
0, 0, 0, 0
</OnPlatform.iOS>
<OnPlatform.Android>
0, 0, 0, 5
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.Padding>
<recycle:RecycleListView.ItemTemplate>
<DataTemplate>
<viewCells:NewsFeedListItem/>
</DataTemplate>
</recycle:RecycleListView.ItemTemplate>
</recycle:RecycleListView> </Grid>


There RecycleListView is a renderer.



Renderer:



    protected RecyclerView _recyclerView;
protected RecycleListViewAdapter _adapter;
protected SwipeRefreshLayout _refresh;
protected RecyclerView.ItemDecoration _itemDecoration;
protected RecycleScrollListener _scrollListener;

protected override void OnElementChanged(ElementChangedEventArgs<RecycleListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
CreateNativeElement();
SetNativeControl(_refresh);
}
}

protected void CreateNativeElement()
{
_recyclerView = new RecyclerView(Android.App.Application.Context);
_recyclerView.HasFixedSize = true;
_recyclerView.SetLayoutManager(new LinearLayoutManager(Context, OrientationHelper.Vertical, false));
_recyclerView.SetItemAnimator(new DefaultItemAnimator());
_recyclerView.HorizontalScrollBarEnabled = false;
_recyclerView.VerticalScrollBarEnabled = true;
var pool = _recyclerView.GetRecycledViewPool();
pool.SetMaxRecycledViews(RecycleListViewAdapter.ADVERTISEMENT_VIEW_TYPE, 1);
pool.SetMaxRecycledViews(RecycleListViewAdapter.DEFAULT_VIEW_TYPE, 25);

_scrollListener = new RecycleScrollListener();
_scrollListener.Loading += (object sender, EventArgs args) => { OnLoadMore(); };

UpdateIsLoadMoreEnabled();

_adapter = new RecycleListViewAdapter(
Context,
Element.ItemsSource,
_recyclerView,
Element,
Resources.
DisplayMetrics,
Element.IsAdvertisementEnabled,
Element.ShowAdvertisementEvery);

_recyclerView.SetAdapter(_adapter);

_itemDecoration = new SpacesItemDecoration(
ConvertDpToPixels(Element.RowSpacing),
ConvertDpToPixels(Element.ItemMargin.Left),
ConvertDpToPixels(Element.ItemMargin.Top),
ConvertDpToPixels(Element.ItemMargin.Right),
ConvertDpToPixels(Element.ItemMargin.Bottom)
);

_recyclerView.AddItemDecoration(_itemDecoration);

_refresh = new SwipeRefreshLayout(Android.App.Application.Context);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(_recyclerView, LayoutParams.MatchParent);
}









share|improve this question

























  • Could you please post more detailed codes? or maybe share a basic demo that can reproduce the problem through online repo?

    – York Shen
    Nov 26 '18 at 7:13











  • @YorkShen-MSFT I added code

    – Viktor Bylbas
    Nov 27 '18 at 13:27


















0















I have a problem only on Android. My items in Listview don't update sometimes. I open a view and I see item without text or space (screen 1-2). I scroll down and then scroll up. Item redrawes and text is shown or space is removed (screen 3)
How can I fix it?
Below are the pictures:




  1. https://i.stack.imgur.com/iv0RC.png


  2. https://i.stack.imgur.com/Kdjs8.png


  3. https://i.stack.imgur.com/FJ4JJ.png



My List:



    <Grid BackgroundColor="{Binding ListViewCustomizer.DefaultBackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<recycle:RecycleListView ItemsSource="{Binding NewsFeedItems}"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
ShowAdvertisementEvery="10"
ItemSelected="HandleItemSelected" RefreshCommand="{Binding RefreshCommand}"
RowSpacing="0" ItemMargin="0"
LoadMoreCommand="{Binding LoadMoreCommand}"
IsLoadMoreEnabled="True"
IsLoadingMore="{Binding IsOldestLoading}"
IsRefreshing="{Binding IsRefreshing}"
IsPullToRefreshEnabled="True">
<recycle:RecycleListView.IsAdvertisementEnabled>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>
false
</OnPlatform.iOS>
<OnPlatform.Android>
true
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.IsAdvertisementEnabled>
<recycle:RecycleListView.ItemHeight>
<extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
</recycle:RecycleListView.ItemHeight>
<recycle:RecycleListView.Padding>
<OnPlatform x:TypeArguments="Thickness">
<OnPlatform.iOS>
0, 0, 0, 0
</OnPlatform.iOS>
<OnPlatform.Android>
0, 0, 0, 5
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.Padding>
<recycle:RecycleListView.ItemTemplate>
<DataTemplate>
<viewCells:NewsFeedListItem/>
</DataTemplate>
</recycle:RecycleListView.ItemTemplate>
</recycle:RecycleListView> </Grid>


There RecycleListView is a renderer.



Renderer:



    protected RecyclerView _recyclerView;
protected RecycleListViewAdapter _adapter;
protected SwipeRefreshLayout _refresh;
protected RecyclerView.ItemDecoration _itemDecoration;
protected RecycleScrollListener _scrollListener;

protected override void OnElementChanged(ElementChangedEventArgs<RecycleListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
CreateNativeElement();
SetNativeControl(_refresh);
}
}

protected void CreateNativeElement()
{
_recyclerView = new RecyclerView(Android.App.Application.Context);
_recyclerView.HasFixedSize = true;
_recyclerView.SetLayoutManager(new LinearLayoutManager(Context, OrientationHelper.Vertical, false));
_recyclerView.SetItemAnimator(new DefaultItemAnimator());
_recyclerView.HorizontalScrollBarEnabled = false;
_recyclerView.VerticalScrollBarEnabled = true;
var pool = _recyclerView.GetRecycledViewPool();
pool.SetMaxRecycledViews(RecycleListViewAdapter.ADVERTISEMENT_VIEW_TYPE, 1);
pool.SetMaxRecycledViews(RecycleListViewAdapter.DEFAULT_VIEW_TYPE, 25);

_scrollListener = new RecycleScrollListener();
_scrollListener.Loading += (object sender, EventArgs args) => { OnLoadMore(); };

UpdateIsLoadMoreEnabled();

_adapter = new RecycleListViewAdapter(
Context,
Element.ItemsSource,
_recyclerView,
Element,
Resources.
DisplayMetrics,
Element.IsAdvertisementEnabled,
Element.ShowAdvertisementEvery);

_recyclerView.SetAdapter(_adapter);

_itemDecoration = new SpacesItemDecoration(
ConvertDpToPixels(Element.RowSpacing),
ConvertDpToPixels(Element.ItemMargin.Left),
ConvertDpToPixels(Element.ItemMargin.Top),
ConvertDpToPixels(Element.ItemMargin.Right),
ConvertDpToPixels(Element.ItemMargin.Bottom)
);

_recyclerView.AddItemDecoration(_itemDecoration);

_refresh = new SwipeRefreshLayout(Android.App.Application.Context);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(_recyclerView, LayoutParams.MatchParent);
}









share|improve this question

























  • Could you please post more detailed codes? or maybe share a basic demo that can reproduce the problem through online repo?

    – York Shen
    Nov 26 '18 at 7:13











  • @YorkShen-MSFT I added code

    – Viktor Bylbas
    Nov 27 '18 at 13:27














0












0








0








I have a problem only on Android. My items in Listview don't update sometimes. I open a view and I see item without text or space (screen 1-2). I scroll down and then scroll up. Item redrawes and text is shown or space is removed (screen 3)
How can I fix it?
Below are the pictures:




  1. https://i.stack.imgur.com/iv0RC.png


  2. https://i.stack.imgur.com/Kdjs8.png


  3. https://i.stack.imgur.com/FJ4JJ.png



My List:



    <Grid BackgroundColor="{Binding ListViewCustomizer.DefaultBackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<recycle:RecycleListView ItemsSource="{Binding NewsFeedItems}"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
ShowAdvertisementEvery="10"
ItemSelected="HandleItemSelected" RefreshCommand="{Binding RefreshCommand}"
RowSpacing="0" ItemMargin="0"
LoadMoreCommand="{Binding LoadMoreCommand}"
IsLoadMoreEnabled="True"
IsLoadingMore="{Binding IsOldestLoading}"
IsRefreshing="{Binding IsRefreshing}"
IsPullToRefreshEnabled="True">
<recycle:RecycleListView.IsAdvertisementEnabled>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>
false
</OnPlatform.iOS>
<OnPlatform.Android>
true
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.IsAdvertisementEnabled>
<recycle:RecycleListView.ItemHeight>
<extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
</recycle:RecycleListView.ItemHeight>
<recycle:RecycleListView.Padding>
<OnPlatform x:TypeArguments="Thickness">
<OnPlatform.iOS>
0, 0, 0, 0
</OnPlatform.iOS>
<OnPlatform.Android>
0, 0, 0, 5
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.Padding>
<recycle:RecycleListView.ItemTemplate>
<DataTemplate>
<viewCells:NewsFeedListItem/>
</DataTemplate>
</recycle:RecycleListView.ItemTemplate>
</recycle:RecycleListView> </Grid>


There RecycleListView is a renderer.



Renderer:



    protected RecyclerView _recyclerView;
protected RecycleListViewAdapter _adapter;
protected SwipeRefreshLayout _refresh;
protected RecyclerView.ItemDecoration _itemDecoration;
protected RecycleScrollListener _scrollListener;

protected override void OnElementChanged(ElementChangedEventArgs<RecycleListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
CreateNativeElement();
SetNativeControl(_refresh);
}
}

protected void CreateNativeElement()
{
_recyclerView = new RecyclerView(Android.App.Application.Context);
_recyclerView.HasFixedSize = true;
_recyclerView.SetLayoutManager(new LinearLayoutManager(Context, OrientationHelper.Vertical, false));
_recyclerView.SetItemAnimator(new DefaultItemAnimator());
_recyclerView.HorizontalScrollBarEnabled = false;
_recyclerView.VerticalScrollBarEnabled = true;
var pool = _recyclerView.GetRecycledViewPool();
pool.SetMaxRecycledViews(RecycleListViewAdapter.ADVERTISEMENT_VIEW_TYPE, 1);
pool.SetMaxRecycledViews(RecycleListViewAdapter.DEFAULT_VIEW_TYPE, 25);

_scrollListener = new RecycleScrollListener();
_scrollListener.Loading += (object sender, EventArgs args) => { OnLoadMore(); };

UpdateIsLoadMoreEnabled();

_adapter = new RecycleListViewAdapter(
Context,
Element.ItemsSource,
_recyclerView,
Element,
Resources.
DisplayMetrics,
Element.IsAdvertisementEnabled,
Element.ShowAdvertisementEvery);

_recyclerView.SetAdapter(_adapter);

_itemDecoration = new SpacesItemDecoration(
ConvertDpToPixels(Element.RowSpacing),
ConvertDpToPixels(Element.ItemMargin.Left),
ConvertDpToPixels(Element.ItemMargin.Top),
ConvertDpToPixels(Element.ItemMargin.Right),
ConvertDpToPixels(Element.ItemMargin.Bottom)
);

_recyclerView.AddItemDecoration(_itemDecoration);

_refresh = new SwipeRefreshLayout(Android.App.Application.Context);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(_recyclerView, LayoutParams.MatchParent);
}









share|improve this question
















I have a problem only on Android. My items in Listview don't update sometimes. I open a view and I see item without text or space (screen 1-2). I scroll down and then scroll up. Item redrawes and text is shown or space is removed (screen 3)
How can I fix it?
Below are the pictures:




  1. https://i.stack.imgur.com/iv0RC.png


  2. https://i.stack.imgur.com/Kdjs8.png


  3. https://i.stack.imgur.com/FJ4JJ.png



My List:



    <Grid BackgroundColor="{Binding ListViewCustomizer.DefaultBackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<recycle:RecycleListView ItemsSource="{Binding NewsFeedItems}"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
ShowAdvertisementEvery="10"
ItemSelected="HandleItemSelected" RefreshCommand="{Binding RefreshCommand}"
RowSpacing="0" ItemMargin="0"
LoadMoreCommand="{Binding LoadMoreCommand}"
IsLoadMoreEnabled="True"
IsLoadingMore="{Binding IsOldestLoading}"
IsRefreshing="{Binding IsRefreshing}"
IsPullToRefreshEnabled="True">
<recycle:RecycleListView.IsAdvertisementEnabled>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>
false
</OnPlatform.iOS>
<OnPlatform.Android>
true
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.IsAdvertisementEnabled>
<recycle:RecycleListView.ItemHeight>
<extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
</recycle:RecycleListView.ItemHeight>
<recycle:RecycleListView.Padding>
<OnPlatform x:TypeArguments="Thickness">
<OnPlatform.iOS>
0, 0, 0, 0
</OnPlatform.iOS>
<OnPlatform.Android>
0, 0, 0, 5
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.Padding>
<recycle:RecycleListView.ItemTemplate>
<DataTemplate>
<viewCells:NewsFeedListItem/>
</DataTemplate>
</recycle:RecycleListView.ItemTemplate>
</recycle:RecycleListView> </Grid>


There RecycleListView is a renderer.



Renderer:



    protected RecyclerView _recyclerView;
protected RecycleListViewAdapter _adapter;
protected SwipeRefreshLayout _refresh;
protected RecyclerView.ItemDecoration _itemDecoration;
protected RecycleScrollListener _scrollListener;

protected override void OnElementChanged(ElementChangedEventArgs<RecycleListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
CreateNativeElement();
SetNativeControl(_refresh);
}
}

protected void CreateNativeElement()
{
_recyclerView = new RecyclerView(Android.App.Application.Context);
_recyclerView.HasFixedSize = true;
_recyclerView.SetLayoutManager(new LinearLayoutManager(Context, OrientationHelper.Vertical, false));
_recyclerView.SetItemAnimator(new DefaultItemAnimator());
_recyclerView.HorizontalScrollBarEnabled = false;
_recyclerView.VerticalScrollBarEnabled = true;
var pool = _recyclerView.GetRecycledViewPool();
pool.SetMaxRecycledViews(RecycleListViewAdapter.ADVERTISEMENT_VIEW_TYPE, 1);
pool.SetMaxRecycledViews(RecycleListViewAdapter.DEFAULT_VIEW_TYPE, 25);

_scrollListener = new RecycleScrollListener();
_scrollListener.Loading += (object sender, EventArgs args) => { OnLoadMore(); };

UpdateIsLoadMoreEnabled();

_adapter = new RecycleListViewAdapter(
Context,
Element.ItemsSource,
_recyclerView,
Element,
Resources.
DisplayMetrics,
Element.IsAdvertisementEnabled,
Element.ShowAdvertisementEvery);

_recyclerView.SetAdapter(_adapter);

_itemDecoration = new SpacesItemDecoration(
ConvertDpToPixels(Element.RowSpacing),
ConvertDpToPixels(Element.ItemMargin.Left),
ConvertDpToPixels(Element.ItemMargin.Top),
ConvertDpToPixels(Element.ItemMargin.Right),
ConvertDpToPixels(Element.ItemMargin.Bottom)
);

_recyclerView.AddItemDecoration(_itemDecoration);

_refresh = new SwipeRefreshLayout(Android.App.Application.Context);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(_recyclerView, LayoutParams.MatchParent);
}






listview xamarin.forms xamarin.android listviewitem






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 13:27







Viktor Bylbas

















asked Nov 23 '18 at 20:43









Viktor BylbasViktor Bylbas

1031112




1031112













  • Could you please post more detailed codes? or maybe share a basic demo that can reproduce the problem through online repo?

    – York Shen
    Nov 26 '18 at 7:13











  • @YorkShen-MSFT I added code

    – Viktor Bylbas
    Nov 27 '18 at 13:27



















  • Could you please post more detailed codes? or maybe share a basic demo that can reproduce the problem through online repo?

    – York Shen
    Nov 26 '18 at 7:13











  • @YorkShen-MSFT I added code

    – Viktor Bylbas
    Nov 27 '18 at 13:27

















Could you please post more detailed codes? or maybe share a basic demo that can reproduce the problem through online repo?

– York Shen
Nov 26 '18 at 7:13





Could you please post more detailed codes? or maybe share a basic demo that can reproduce the problem through online repo?

– York Shen
Nov 26 '18 at 7:13













@YorkShen-MSFT I added code

– Viktor Bylbas
Nov 27 '18 at 13:27





@YorkShen-MSFT I added code

– Viktor Bylbas
Nov 27 '18 at 13:27












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452740%2fxamarin-forms-redraw-listview-items%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452740%2fxamarin-forms-redraw-listview-items%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]