Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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.

 
Rancher
Posts: 3164
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: 59414
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid that doesn't answer Norm's question.
 
Norm Radder
Rancher
Posts: 3164
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: 1692
68
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: 1692
    68
    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.
     
    Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
    Why should you try IntelliJ IDEA ?
    https://coderanch.com/wiki/696337/IntelliJ-IDEA
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!