问题
I'm getting inbox folder of my gmail account, can list the incoming e-mails, but that list is being listed from older mails to newer mails. How can i revert that ?
public class readInbox extends ListActivity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//setContentView(R.layout.readmail);
Message[] messages = new Message[] { };
try {
messages = inboxReader.getMail();
}
catch (MessagingException e) {
Log.e("mailReader getMail error. in readmail.java", e.getMessage(), e);
}
ArrayAdapter<Message> adapter = new ArrayAdapter<Message>(this,
R.layout.simple_list_item_1 ,messages){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Message message = getItem(position);
TextView resultView = new TextView(super.getContext());
try {
resultView.setText(message.getSubject());
}
catch (MessagingException e) {
Log.e("resultView.setText in readmail", e.getMessage(), e);
}
return resultView;
}
};
setListAdapter(adapter);
}
}
回答1:
either invert the order of the array , or for the getItem
, use the reverted index (count-position-1) .
btw, that's not an efficient way to use listviews , and in fact it has a memory leak which will cause it to crash after a lot of items (about 10000 is enough for SGS3) .
for more information about listView , check this video:
http://www.google.com/events/io/2010/sessions/world-of-listview-android.html
回答2:
You can get the total number of messages through inbox.getMessageCount()
, then retrieve last N number of messages.
Message messages[] = inbox.getMessages(inbox.getMessageCount() - 25 , inbox.getMessageCount());
来源:https://stackoverflow.com/questions/9101615/listing-inbox-with-javamail-api