java - How to add element to this array? -
this question has reply here:
how add together new elements array? 12 answersis there way add together new items array?
rowmsg rowmsg_data[] = new rowmsg[] { new rowmsg(r.drawable.ic_launcher, "message 1"), new rowmsg(r.drawable.ic_launcher, "message 2"), new rowmsg(r.drawable.ic_launcher, "message 3"), new rowmsg(r.drawable.ic_launcher, "message 4") }; // here want add together next 1 element, example: rowmsg(r.drawable.ic_launcher, "message 5")
no. can't add together elements arrays - 1 time you've created array, size can't change.
you'd improve off list:
list<rowmsg> messages = new arraylist<rowmsg>(); messages.add(new rowmsg(r.drawable.ic_launcher, "message 1")); // etc as aside, it's more conventional maintain type info in 1 place, , java variables conventionally camel-cased - if did stick array, improve declare as:
rowmsg[] rowmsgdata = new rowmsg[] { ... }; (i'd suggest avoiding abbreviations, there go.)
java android
No comments:
Post a Comment