• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Copy Data Between ArrayLists of Different Types

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79076
376
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am afraid that doesn't answer Norm's question.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 84
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
    reply
      Bookmark Topic Watch Topic
    • New Topic