Passing an array of GeoCodes from 1 intent to another - android

Just wondering what the best way to pass an array list of GeoCodes is?
I can seem to put the arraylist into the intent okay using
saveRouteIntent.putExtra("waypoints", waypoints);
But I cant see how I would get the list in the new activity.
I could build two double arraylists and pass them across and then create the geocode array list again on the other side but im assuming there is a better method?

Use serializable while passing data through putExtra()
First Activity:
ArrayList<String> waypoints= new ArrayList<String>();
saveRouteIntent.putExtra("waypoints", waypoints);
In the other Activity:
ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra("waypoints");

If its an array you can use serializable to putExtra() , but in this case you'll have to implement your own subclass that extends BasicNameValuePair , for a perfect implementation try this.

Related

How to manage full change of a recycler-adapter in android

I'm trying to figure out how to manage an adapter and the corresponding recyclerview appropriately.
The situation is the following:
I'm doing search queries on a database, and each time a new search is entered the whole dataset may change. Should I instantiate a new adapter each time? Or should I just remove items (even all items) from the adapter and insert new ones? Or something else?
EDIT: I should explain the situation better.
I'm using Algolia to store some data, which is retrieved in JSON objects.
Then the JSONArray obtained is passed as string to the adapter, which will parse each element in the string and the corresponding data of each element.
Since the searches are issued each time a new character is written (or removed), each time I obtain a new JSON response, it could be similar, the same, or completely different than the previous one.
You can do the following
mAdapter.notifyDataSetChanged();
or you can do ,
mAdapter.notifyItemRangeChanged(position, list.size());
Also, you can try the following to update recycler view
recyclerView.setAdapter(new RecyclerViewAdapter(newList));
recyclerView.invalidate();
just add new function for update the list
public void updateList(List<DataHolder> list){
displayedList = list;
notifyDataSetChanged();
}

How to pass a multidimensional double array in Android?

I am trying to pass my double array from one activity to the other. However I cannot figure out how to do this, as the methods I' ve tried just give me error messages.
This is what I' ve tried in my MainActivity:
intent.putExtra("nutritional_value", temp.nutritional_value);
(in case necessary: I have defined the variable 'temp' in a third java class like this):
SingleItem temp = list.get(position);
This is what I' ve tried to do in my second activity:
double[][] nutritional_value = intent.getDoubleArrayExtra("nutritional_value", 0);
I' m not exactly new to Android but I' m still in the learning curve, please tell me if you know how I can fix this, I would really appreciatie it.
Thanks
Try serialzing the array, something along the lines of
double[][] nutritional_value =....
Bundle bundle = new Bundle();
bundle.putSerializable("array_array", nutritional_value );
You can't like that. putExtra doesn't take multidimentsional . You'll need to either:
Wrap it in a Parcelable class you will have to write.
Serialize it in some other way. Gson to string for example. Gson will cope with multidimensional arrays.
getDoubleArrayExtra refers to a single dimensional array of double values.

Pass hashmap to array adapter in Android

I just want to pass a hashmap to array adapter in android. It is not going to be used for display. It is for some manipulation purpose. For display already a arraylist is passed.
Suggest how to just pass hashmap to adapter ?
Thanks in advance.
two possibilities
Add a parameter to the Constructor
create a setter
of course you have to write your own subclass of ArrayAdapter

extends BaseAdapter results are overwrite previous ArrayList Items

i have a DateApapter class like this..
public class DateAdapter extends BaseAdapter
{
...
}
i call this DateApapter in 12 different places from my "mainActivity" by using constructor and store this result in a DateApapter object "mDefaultAdapter " like this..
mDefaultAdapter = new DateAdapter(this,days,sysDate,disablePastDays, selectedDateTypeDf);
and stored this various results of mDefaultAdapter in ArrayList like this..
ArrayList<DateAdapter> mDefaultAdapterList = new ArrayList<DateAdapter>();
mDefaultAdapterList.add(mDefaultAdapter);
now coming to the problem,
In my 1st call DateAdapter constructor , it returns January month
details and I add this result(January) to ArrayList its works fine.
Now the ArrayList has one Item, that is January details.
but when i call 2nd result(February) to arrayList its overwrite 1st
result also. Now the ArrayList has two Items, both of the items
are February details.
That means Last result of DateAdapter is filled the whole ArrayList.
Finally i got December details only from ArrayList.
Why DateAdapter results are overwrite in previous ArrayList Items?
I am not using any Static variables or methods in whole program.
Please help me to fix this problem. Thanks..
I'm not really sure what's happening with your adapter. Maybe you're using the same ArrayList object with all the adapters.
But I think you should reconsider your approach.
Here's what I would do.
1- Store the calendar events in an SQLite database.
2- In your FragmentPagerAdapter, pass the position to your Calendar Fragment.
3- In your Calendar Fragment, retrieve the position ( 0 : January - 11 : December) and query your database to retrieve the events.
It was my mistake.. The problem is Illegal object reference overwrite my previous ArrayList Items.
I saved myself by making a separate object for Date Adapter.

passing an arraylist from one intent to another

am trying to pass an arrylist from one intent to another.
My code is as follows:
intent.putExtra("near_places", nearPlaces);
intent.putExtra("nearby", nearbylist);
and at the new intent i do this:
nearPlaces = (PlacesList) extras.getSerializable("near_places");
nearbylist = (ArrayList<FsqVenue>)extras.getArrayList("nearby");
the code for the firat is correct but for the second it shows me errors where fsqVenue is a class
please help me
first make sure FsqVenue class implements Serializable interface then use this code for getting ArrayList in other Activity :
nearbylist = (ArrayList<FsqVenue>)extras.getSerializable("nearby");
In your receiving intent you need to do:
Intent i = getIntent();
near_places = i.getStringArrayListExtra("nearPlaces");
that's perfect work please try and give replay.
Princewill, here is your answer :- I want to let user add multiple items by action sequence, i have done this and looking for to make it more advanced.....JUST OPEN LINK AND VIEW code for Catalogue and SingleMenuItem Activity and done.

Categories

Resources