convert ArrayList to string[]

后端 未结 2 1974
一个人的身影
一个人的身影 2021-01-28 01:37

I have class Person

class person{
int ID ;
sting FirstName ;
string Last Name ;
String Telephone ;

}

and I have ArrayList

相关标签:
2条回答
  • 2021-01-28 02:08

    Make your ArrayAdapter to use the type person and not String (also, just pass the ArrayList<person> instead of an array) like this:

    ArrayAdapter<person> modeAdapter = new ArrayAdapter<person>(this, android.R.layout.simple_list_item_1, android.R.id.text1, theArrayList);
    

    and then override the person's class toString method:

    class person {
            int ID;
            String FirstName;
            String LastName;
            String Telephone;
    
            @Override
            public String toString() {          
                return "Whatever " + FirstName + " and Whatever  " + LastName;
            }
    
        }
    
    0 讨论(0)
  • 2021-01-28 02:09

    Better to use Custom Adapter. Here you do not need to convert ArrayList to String ArrayList. You able to set data via array-list position.

    link

    Thanks

    0 讨论(0)
提交回复
热议问题