This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Copy Data Between ArrayLists of Different Types  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two ArrayLists of different types:



AND



In my private method , I need to copy all of the data from first ArrayList to the second ArrayList.

 
Master Rancher
Posts: 3276
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a method that can convert the objects in the source ArrayList to the datatype the target ArrayList takes?
Then write a loop to access, convert and store each item.

Are the classes related at all?  Is one the super of the other?
 
Adam Wentz
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Do you have a method that can convert the objects in the source ArrayList to the datatype the target ArrayList takes?
Then write a loop to access, convert and store each item.

Are the classes related at all?  Is one the super of the other?




I am using PackageManager to get a list of user-installed applications. They are stored in installedApps.

I need to display them in a ListView, but I can't get the array from the PackageManager to display to the ListView, so I was going to copy the data to an intermediary ArrayList, which is what listApps is for.
 
Marshal
Posts: 60095
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid that doesn't answer Norm's question.
 
Norm Radder
Master Rancher
Posts: 3276
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are the datatypes of the elements in the two ArrayLists different?  It would be simpler if they were the same.

I can't get the array from the PackageManager to display to the ListView


What is the problem?  Copy full text of any error messages and paste it here.
 
Saloon Keeper
Posts: 1844
80
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adam Wentz wrote:I need to display them in a ListView, but I can't get the array from the PackageManager to display to the ListView, so I was going to copy the data to an intermediary ArrayList, which is what listApps is for.


I was able to find a few examples of this sort of thing looking for "PackageManager to display to the ListView" in Google which are listed below:
  • http://www.androprogrammer.com/2013/10/get-installed-application-in-list-view.html
  • https://xjaphx.wordpress.com/2011/06/12/create-application-launcher-as-a-list/
  • http://stacktips.com/tutorials/android/how-to-get-list-of-installed-apps-in-android
  • http://theopentutorials.com/tutorials/android/listview/how-to-get-list-of-installed-apps-in-android/

  • Maybe you should be look into the RecyclerView which has largely replaced ListView.
    Don't get me wrong, ListView have they purposes and they are still 100% valid, but a RecyclerView can do everything a ListView can and more.
    However the ListView cannot do everything that the RecyclerView can do (or not at easily).
     
    Adam Wentz
    Ranch Hand
    Posts: 77
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Pete Letkeman wrote:

    Adam Wentz wrote:I need to display them in a ListView, but I can't get the array from the PackageManager to display to the ListView, so I was going to copy the data to an intermediary ArrayList, which is what listApps is for.


    I was able to find a few examples of this sort of thing looking for "PackageManager to display to the ListView" in Google which are listed below:
  • http://www.androprogrammer.com/2013/10/get-installed-application-in-list-view.html
  • https://xjaphx.wordpress.com/2011/06/12/create-application-launcher-as-a-list/
  • http://stacktips.com/tutorials/android/how-to-get-list-of-installed-apps-in-android
  • http://theopentutorials.com/tutorials/android/listview/how-to-get-list-of-installed-apps-in-android/

  • Maybe you should be look into the RecyclerView which has largely replaced ListView.
    Don't get me wrong, ListView have they purposes and they are still 100% valid, but a RecyclerView can do everything a ListView can and more.
    However the ListView cannot do everything that the RecyclerView can do (or not at easily).




    Thanks, Pete! I ended up finding what I needed in this tutorial you referenced: http://theopentutorials.com/tutorials/android/listview/how-to-get-list-of-installed-apps-in-android/
     
    Pete Letkeman
    Saloon Keeper
    Posts: 1844
    80
    Android Chrome IntelliJ IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You are welcome Adam. I'm glad that you were able to come up with a solution for your problem.
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!