How to place Multiple MapViews v1 inside a ViewFlipper - android

Objective- I want to show slide shows of different Map Activities which show data according to database, using view flipper(or something similar).
Issues:
View Flipper can't be added to an Activity that is not a MapActivity if flipper contains a mapview.
View Flipper does not allows adding multiple mapviews as one MapActivity can have only one map view.
What I wish to implement
Want to show slide show of multiple MapActivities which show markers,route etc based on database data.
Want to refresh these MapActivities also new data is fetched periodically and database is updated.
I'am unable to find a solution to my problem. I have gone through the following links but they provided no relevant solution:
How can i Implement SlideShow in android?
Can a MapView be placed inside a ViewFlipper somehow?
Please help and suggest what is the best approach for this problem.
Thanks!

I did not find standard solution to my problem as view flipper could not be used.I did the following to implement mapview slide show. Its more of a hack than a proper solution but I had no choice.
In a while loop, I kept re-rendering the same map view in the async map task.
2.After 1st map is loaded I called thread.sleep(10000).
3.I cleared the mapview of all routes and markers.
4.I re rendered the 2nd map view.
5.And the steps were repeated continuously.
#Override
protected Void doInBackground(Void... params) {
final Drawable marker_inBetween;
marker_inBetween = getResources().getDrawable(R.drawable.blue_pin);
marker_inBetween.setBounds(0, 0,
marker_inBetween.getIntrinsicWidth(),
marker_inBetween.getIntrinsicHeight());
helper = new DbHelper(getApplicationContext());
// show slide show
while (true) {
ArrayList<String> IdList =showAllPeopleOnMap();
util.haveASleep(slideShowInterval);
showEachPersonRouteOnMap(IdList);
resetVariables();//resets lists,routes,removes markers etc
}
}
return null;
}
Thanks.

Related

Adding and Deleting between two seperate Array ListViews

I want to create a custom ListView.
Initially, the custom ListView has one array of data, but when user taps one of the list items, it's then removed from current array and added to another. If the user taps on the second array, the list item is then added back over into the first array.
Please suggest how to apply logic to do this.
Updates : I wants to use only one listview/recyclerview.
Following are screen shots..
Regarding the object switch - this is a simple transfer between lists, , just know beforehand if the insertion and removal is index based, e.g:
contacts.add(iLocation, ContactObject);
favorites.remove(iOtherLocation);
Regarding the ListView stuff, I would suggest converting to RecyclerView, let's build a general scenario:
You have a screen (Activity or Fragment) that holds one list (the implementation can be ListView or Recycler), and another screen that holds the other list.
In both of your lists you have adapters in which you implement the logic for the clicks on the objects in the lists.
The click transfers the object, either directly to the other list, OR to a temporary Object holder (because you might need it for other stuff), in which case you will need to pull that object from the other view, either way you remove it from the current one.
you switch to the other view, and refresh it.
An easy way to go -
Assuming the screens are the same, use only one Activity, holding a single RecyclerView, and handle 2 adapters, each for every list, the adapters allow you to handle the clicks easily, with an index for the object clicked, the click executes the info swap action,the Activity handles the visual swap Action.
a very general example would be:
//init everything obviously ;)
List<ContactObject> contacts;
List<ContactObject> favoritesContacts;
//the AdapteListener is an interface declared inside the adapter
mContactsRecyclerAdapter = new ContactsRecyclerAdapter(this, contacts,new ContactsRecyclerAdapter.AdapterListener()
{
#Override
public void cellClicked(int iIndex, ContactObject object)
{
favoritesContacts.add(iIndex, ContactObject);
contacts.remove(iIndex);
mContactsRecyclerAdapter.notifyDataSetChanged();
mFavoritesRecyclerAdapter.notifyDataSetChanged();
mRecyclerView.swapAdapter(mFavoritesRecyclerAdapter, false);
}
});
And vice-versa for the other adapter.
Hope this helps, comment if you have problems and I'll update.
Please implements with custom view extend with Linearlayout
Custom view has 2 child Linearlayout in which will add with this custom view
First time add all the element in first Linearlayout and based on user action please remove from first Linearlayout and add it in another layout

How to reference a Fragment in an android list adapter

I am trying to add small maps to a list and have created a Cursor adapter to handle a list of locations.
The layout for the individual location looks like this:
<LinearLayout
... >
<TextView android:id="#+id/start_loc"
...
/>
<fragment android:id="#+id/start_loc_map"
android:name="com.google.android.gms.maps.MapFragment"
...
/>
</LinearLayout>
Then in the adapter:
#Override
public void bindView(View view, Context context, Cursor cursor) {
startLocView = (TextView) view.findViewById(R.id.start_loc);
then something like:
SupportMapFragment startLocMap =
(SupportMapFragment) view.findViewById(R.id.start_loc_map);
or:
SupportMapFragment startLocMap =
(SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.start_loc_map);
Neither of these works. The view (not surprisingly) can't be cast as a fragment and there is no fragment or activity available to the adapter. I can get a Context and (Activity) context.getFragmentManager but I can't find any way to get to getChildFragmentManager from that. I can get a FrameLayout, which is what the container object is but I don't know any way to reference to the Fragment contained therein.
How do I get a reference to a static (?) fragment in a layout from an adapter? Is getting a <fragment> less straightforward than a <TextView>?
There would be a lot of work to display map in the list view using cursor adapter. The other problem that you shall be facing is the degraded performance and frequent app crash. Direct use of the mapView in a listView is a heavy operation. This is going to cause a delay and result will be sluggish User Experience of your app. To avoid this behavior you have an alternative to use Static maps. This will enable Lazy Loading of maps in your list view and therby user wont have to tap map now and then. If you are not providing current location of the user on the map litview Static maps are the best option.
I am providing a small example below that use this method. First create a list view from the data (Either API or DB). Then pass data such as latitude and longitude to a string with some static variables defined as follows.
String getMapURL = "http://maps.googleapis.com/maps/api/staticmap?zoom=12&size=360x180&markers=size:mid|color:green|"
+ JOLocation.getString("latitude")
+ ","
+ JOLocation.getString("longitude")
+ "&sensor=false";
The above constructed URL, when used in a browser, returns a .PNG file. Then, in my adapter for the activity, This method results in the lazy loading of the maps in the app where your marker displaying the coordinates are fetched at runtime, avoiding heavy work in the code.
Hope this would help!!!

Correct approach for async ListFragment

I'm pretty new to Android and I'm finding it difficult to figure out the correct/best way to accomplish the following:
I'm using ActionBarSherlock to have a set of tabs that each load a fragment. One of these is a ListFragment (actually SherlockListFragment). I started off by simply using a new thread to load the list, and all seemed fine, until you switch to a different tab before the list has loaded. Then it fails at SetListShown(true) because I guess the fragment is not active.
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
SetListShown(false);
var listView = (ListView) Activity.FindViewById(Android.Resource.Id.List);
Button loadMore = new Button(Activity);
loadMore.SetText("Load more articles", TextView.BufferType.Normal);
loadMore.Click += LoadMoreArticles;
listView.AddFooterView(loadMore);
ThreadPool.QueueUserWorkItem((obj) => {
var articles = _articleService.GetArticles(0, 10, DateTime.UtcNow);
_items = articles.Select(x => new ArticleSummaryModel(x)).ToList();
Activity.RunOnUiThread(() => {
_adapter = new ArticleList_Adapter(Activity, _items);
ListAdapter = _adapter;
SetListShown(true);
});
});
}
What I'd like to happen is that when a tab is opened for the first time it starts loading the data, showing the standard progress indicator, then then it completes the list is shown and the progress indicator removed. If the tab is change while data is loading, it should be visible when that tab is opened again.
If there's a simple way to achieve this that I've missed, great! It it's simply not possible with Android, I'd like to know that too so I can stop trying ;-)
I've read a lot about AsyncTask, AsyncTaskLoader, IntentService, etc. but I'm not at all clear what I need to use, and it any of these would actually achieve what I want!
FYI I'm using mono for android and the compatibility pack to support v2.3+, but can hopefully translate any java examples etc.
Many thanks in advance!
Robin
I'm not sure how this would work with monodroid but I'm guessing it should be about the same. Use an AsyncTaskLoader since they are tied to the activity lifecycle through the LoaderManager. You should have your fragments implement the LoaderCallbacks interface and call loaderManager.init(...) somewhere in there (for example, in onActivityCreated). When the loader task is finished you'll be notified in onLoadFinished with the data and there you can load your it into the adapter and do the progressbar and listview transition. You can find examples on how to implement an AsyncTaskLoader on the documentation page here or with a bit more detail here. As for the transition, use something like this which gives some polish to your app.

removing specific overlays from mapview

my problem is as follows.
I am creating multiple itemized overlays. (because every overlay gets a different drawable)
I customized the itemized overlay class, but when i add it to the mapview overlays, the class is transformed into an overlay class.
to make it worse i got 3 classes creating overlays on the same map. each class represents an item on the map with it's own intelligence behind it.
the problem i now have is that i want to remove an overlay, but i can not be sure that the index i inserted it on, is also the index it has when i try to remove it. (the other classes might have inserted an overlay in the mean time)
the classes are self updating, so i do not want a solution that fires an update or delete event from the main class. (the whole point is to add a class and forget about it)
so my question would be: how can i identify which layer is which when i want to call a remove on that layer. i think the information is available, but i do not know how to get to it.
this is the code i am using to add the overlay
OverlayItem overlayitem = new OverlayItem(p,myNaam ,myOmschrijving );
LocationOverlay = new MyLocationOverlay(drawable, myContext);
LocationOverlay.SetLocation(i,overlayitem);
myOverlays.add(LocationOverlay);
You can set a certain integer as a position for every overlays
something like that :
mapView.getOverlays().add(0,myScaleBarOverlay);
and when you want ro remove this call:
mapView.getOverlays().remove(0);
mapView.invalidate();
Regard
You don't have to remove specific layer. You can remove an overlay specified by it's reference (e.g. myOverlay).
LocationOverlay myOverlay = new MyLocationOverlay(drawable, myContext); //`you forgot the name of variable`
mapView.getOverlays().remove(myOverlay);

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