Android - Combining Lists returned from Intent filter
I'll try make this short.
I want to get a list of browsers
installed on the device, as well as a list of apps to handle maps
, eg Google Maps, MapDroyd. I want to display both lists on a custom dialog and depending on which is clicked, load the app with the provided coordinates and the relevant URI.
To load the browser, you just need to pass in a http://
URI, and with map applications, you pass in geo:lat,lon
. My problem is, combining them onto the same list.
Here's my code so far:
final PackageManager packageManager = activity.getPackageManager();
//This gets all the browsers
final String browserURI = httpURL+lat+","+lon;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserURI));
final List<ResolveInfo> browserList = packageManager.queryIntentActivities(browserIntent, 0);
// This gets all the Map apps:
final String mapUri = "geo:"+lat+","+lon;
Intent mapIntent = new Intent(Intent.ACTIO开发者_高级运维N_VIEW, Uri.parse(mapUri));
final List<ResolveInfo> mapList = packageManager.queryIntentActivities(mapIntent, 0);
So here I have browserList
and mapList
which I think contain the list of all the apps I want to display. The problem is how to combine them into a common third list. Is it as simple as ListView.add()
or something?
Ideally, at the end, I want it to pop up the apps and if a user clicks to view it in their browser, it'll open up the http://mysite link, and if they choose to view it in a map app, then it'll launch that app at the specified coordinates.
Thanks for the help.
A ListView requires a ListAdapter. The ListAdapter is what provides the data to the ListView. When you construct the ListAdapter one of the contructor parameters is the data array.
If you need to update the ListView after you have already put the data in the ListAdapter you need to first update the array you had passed in previously and then call notifyDataSetChanged() on your ListAdapter, which you can get from the ListView.
If you are creating both Lists before you are creating your ListView then to combine the two Lists you can do:
browserList.addAll(mapList);
精彩评论