Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add array to listview

I have an array of apps(PInfo) and I am wondering how do I add that array to a listview?

ArrayList<PInfo> info = appsGetter.listPackages();
    int number = 0;
    PInfo appInArray;
    while(number < info.size()){
        appInArray = info.get(number);
}

This is what I have at the moment, the listPackages() is a method that is getting the names of the apps from the device.

At the moment I am trying to get the information out of the array one by one and add it to the listview like that. Is that how I should do it our should I add the array straight to the listview? And how do you do that?

like image 211
Hip Hip Array Avatar asked Aug 09 '26 20:08

Hip Hip Array


1 Answers

You can use an ArrayAdapter and initialize it like this:

ArrayAdapter<PInfo> adapter = new ArrayAdapter(context, 
                android.R.layout.simple_list_item_multiple_choice, 
                info);

Then you can you use ListView.setAdapter(adapter).

I'm not sure if this is what you're asking though. So please clarify further if this is not what you're asking

like image 130
kkudi Avatar answered Aug 11 '26 08:08

kkudi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!