Viewpager OffscreenPageLimit issue - android

I've multiple choice (radio buttons) questions on pages. I'm getting user answers with hashmap. So I set previous question answer on start of next question. As a result I start using set hashmap on start 2.page.
BUT problem is: I think viewpager loads first 2 pages at the same time ; so "set hashmap" on start 2.page goes null ; because 1. page isnt loaded / or just loaded at the same time
How can I get rid of this problem ?
page: list answers (1)
page: get user choice(1), clear list(1), set list answers (2)
page: get user choice(2), clear list(2), set list answers (3) ...
maybe setoffscreenpagelimit 0 could be solution but lowest value is 1

This older answer can probably help you.
Basically you just want to know when another fragment is visible, and update it from there.

Related

Xamarin.Forms Adding Children Pages to TabbedPage

My Main Page in my App is a TabbedPage
I have three Tabs:
Payment, Config, Maintain
One of the tabs is controlled by a setting to show it or not. When that is changed to false I remove the tab by doing the following:
tabPage.Children.Remove(ConfigTab);
This removal works fine. If I turn the tab back on I can Add the tab by using this code:
tabPage.Children.Add(ConfigTab);
But its added at the end of the list and the Navigation header is missing:
I looked at using the Insert method where I can sepcify an index
tabPage.Children.Insert(1,ConfigTab);
but this crashed the app with the following message:
Unhandled Exception: Java.Lang.IndexOutOfBoundsException: Invalid
index 2, size is 2
If I inspect the children at that point it has added the page at the correct index
Any suggestions on how I can dynamically insert a new page to a TabbedPage? And retain the navigation?
UPDATE:
I have now managed to get it working by doing the following :
var paymentPage = tabPage.Children.FirstOrDefault(p=> p.ClassId == "PaymentNavPage");
var configPage = GetConfigPage();
var maintenancePage = tabPage.Children.FirstOrDefault(p => p.ClassId == "MaintaintNavPage");
// Clear old Tabgs
tabPage.Children.Clear();
// Put pages back
tabPage.Children.Add(paymentPage);
tabPage.Children.Add(configPage);
tabPage.Children.Add(maintenancePage);
I'm still interested if there is a better way to use the Insert method and then to reset the Navigation Stack.
I'm experiencing the same thing with Insert to the Children. Your solution seems to be the only option to hide and show a page. I would suggest assigning the pages to variables so you don't have to loop through the Children every time you are hiding/showing ConfigPage. Based on the names I'm assuming that the pages are different from each other.
In the case of similar pages ItemsSource can be used with the help of DataTemplate. When binding the ItemsSource to ObservableCollection hiding and showing pages requires just to modify that collection. More info about that can be found here:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/tabbed-page/#Populating_a_TabbedPage_with_a_Template
The next code work for me:
tabPage.Children.Insert(1,ConfigTab);

xamarin mutli selection listview

It's been a while that i'm trying to get an anwser to my problem, but i didn't find it... So i'm searching for your help.
I work on xamarin to make an android application but i dont use Xamarin.Forms (i would have used it, if i knew it when i begin the project
I'll directly to the point, if you have some question, just ask me.
So i got a Listview where i can select 2 or more items :
private void _listViewIntervention_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
_intervention[e.Position].IsSelected = !_intervention[e.Position].IsSelected;
if (_intervention[e.Position].IsSelected)
e.View.SetBackgroundColor(Android.Graphics.Color.Rgb(255, 127, 127));
else
e.View.SetBackgroundColor(Android.Graphics.Color.Rgb(230, 230, 230));
_numberInterventionSelected.Text = _intervention.FindAll(elem => elem.IsSelected == true).Count().ToString();
}
That thing work but if i have a listview with 20 items i.e and i select 3 items, if i scroll the listview, everything will be disturb and my 3 highlighted rows won't be anymore and the highlight will be on another row that i've never select.
I think that not that evident and it might be blur.
IMO i'm not changing the good thing when i do the "e.View.SetBackgroundColor" but i've try lot of thing that never worked.
I might not going the best way to do what i want to do btw.
The result i want is when i scroll the listview, nothing change so i can select the first and the last item of the listview i.e.
I search again in my side but i count a little on you know...
Thanks for reading and have a good day !
I have already getting same problem after lot of search and find the solution
In Xamarin custom adapter remove ViewHolder System it's working fine after removing Holder system

web service returns 10000 rows of data, how to handle this

this is obviously too much data to display in an android app.. what can i do to mitigate this problem ?
I tried to show all 10000 rows in a list view but i got poor performance. I also tried to display all 10000 rows of data in the list view but that just made it slow
Why do you need that method ? WS method's approach is wrong. First of all, you must change method signature like this (int pageNumber, int recordNumber ) and make pagination enabled. If you use a listview, you can show the first 10 record. Then, if the user need more than that, could click to show more button.

setListAdapter(adapter_name) to change the list displayed on screen, but still appears information from the previous displayed list

I have an activity that extends ListActivity, a list of "concepts" (let's call this list "C") and an onItemClickListener defined for this list. Whenever I click a "concept", no matter which one, the app must display another list. I have the following code to change the displayed list:
if(position == 0) change_list("adapter1");
else if (position == 1) change_list("adapter2");
else if (position == 2) change_list("adapter3");
else if (position == 3) change_list("adapter4");
else if (position == 4) change_list("adapter5");
Where position is the position of the clicked element in C
The function change_list performs setListAdapter(parameter) depending on the parameter I pass.
If I click the first element of C (the first concept), a list related to the first concept must appear. However, after calling setListAdapter(adapter), the data related to this concept is displayed, and also part of the C's list data.
For example: let's suppose C has these concepts:
A B C D E
and I click "A", which would lead to display a list with the following data: {a1,a2}
That's the final result:
a1 a2 C D E
And then, when I interact with another element on screen or I scroll down the list, the "ghost" data disappears and only the correct data remains on screen, just like this:
a1 a2
To make things worse, when I want to display list C again, nothing strange happens. Everything is displayed correctly.
At any time incorrect data is stored where it doesn't have to. One function my app must allow is to generate a txt file , and the generated txt file contains exactly the data I introduced. No data is corrupted or duplicated. I also tried using notifyDataSetChanged() and other functions, but I didn't solve the problem.
EDIT :
Here goes the xml code used for the main list of the activity:
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:layout_below="#+id/afegir"/>
And an example of code in which I determine which contents must be displayed on screen:
else if(comprovar_concepte_actiu() == 1){
pnt = mydbhandler.getStoredValues("despeses1");
pnt.moveToFirst();
if(pnt.moveToFirst()){
do{
adapter_mostrar.add(pnt.getString(pnt.getColumnIndex("nom")));
}while(pnt.moveToNext());
}
adapter_mostrar.notifyDataSetChanged();
}
Where comprovar_concepte_actiu() returns and integer that tells which concept has been clicked in the main list C and adapter_mostrar is the single adapter I'm using now, instead of using multiple adapters (which made me use setListAdapter)
At the beginning of the activity, I call this.setListAdapter(adapter_mostrar). That's all I have.
EDIT 2 :
https://www.dropbox.com/s/7twgy043lkxb2x5/conceptes.java?dl=0
Here is a link to my conceptes.java activity. Press CTRL+F once opened and search "this is where I call.. " and you will directly get to the function where the change of list displayed on screen starts
I haven't found a solution yet. Any idea will be totally appreciated
The problem here is that - when you set a new adapter - the old data is still drawn. In other words, there has been no command to "refresh" the listView. However, the new adapter will be commanded to draw its own views. What ultimately occurs is that the old items are still there, the new items are redrawn, but when scrolled away the new adapter won't redraw/recreate the old items.
The solution is to simply refresh the adapter. However, there are two ways to go about this:
Add a new adapter every time and use myListView.invalidateViews(); or something similar [This is probably the easiest solution to implement, although probably not the best in the long run]
Change the dataset of the adapter and use notifyDataSetChanged() [on the adapter]
The latter option is a far better idea. You should use a single adapter and simply change its data over time. Once its dataset is changed, then tell the adapter that such a thing happened so it refreshes. However, you should read more here on all the different thoughts and processes about it, rather than take my opinion on it.
Edit:
There's apparently some very nicely, thought out answers around. Here's another one, that tells you more specifically about the differences between these two:
Is there any difference between ListView.invalidateViews() and Adapter.notifyDataSetChanged()?
Edit2:
With the onClickListener in mind, invalidateViews() will most likely not work, as it'll probably still draw the old views to "finish" the click (ie, draw the highlighting).
Changing the data directly inside a single adapter and using Adapter.notifyDataSetChanged() is your best bet, as it'll know to redraw everything from a single adapter and use only the current data defined by this single adapter.
Best to leave the data specifics (and defining what to draw based off of that data) up to what actually knows the data, rather than a higher up container that knows nothing specific about the actual data.

Problem with list activity

I have implmented pagination and it display 5 records per page. Now suppose I am on page 3 and click 3'rd element then 3'rd element of page-1 is selected.
I am not able to figure out problem as I always create new list object while setting data.
I used below code
temp = new ArrayList();
this.someListAdapter = new SomeListAdapter(this, R.layout.row_facet,temp);
setListAdapter(this.someListAdapter );
Below is signature of SomeListAdapter class.
public class SomeListAdapter extends ArrayAdapter<VoNeighborhood> {
}
Please help....
There really aren't enough details here about how you do pagination with your ListView.
So I might guess you're overriding onListItemClick and using the position variable it sends you, but you then don't take into account the page you're on?
Alternatively, just don't use pagination as you have an infinite canvas to scroll your list within — I don't think I've recall seeing an Android app so far that uses pagination!

Categories

Resources