I am creating a mail interface that populates a ListView from a database using a custom CursorAdapter. The items in this ListView then display an email stream that populates the ListView using the CursorAdapter in the same way. The problem I ran into is that the second ListView will not populate.
The code for initializing both of these adapters is almost identical (we can say that they are intended for all purposes and tasks), and with the help of the log operators I was able to verify that the cursor passed to the second adapter is not empty and contains all the data it needs. It seems that the problem is that the newView method is never called. I tried to find out why this is happening, and did not come up with anything. I am wondering why the newView method will not be called. Where should this call be called?
Here is the onCreate method for ListActivity.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.email_view);
cursor = EmailActivity.dbAdapter.fetchEmailThread(getIntent().getStringExtra("senderUsername"));
Log.i(TAG, getIntent().getStringExtra("senderUsername") + " " + cursor.getCount() + " " + cursor.getColumnCount());
startManagingCursor(cursor);
adapter = new EmailViewCursorAdapter(this, cursor);
setListAdapter(adapter);
}
And here is the code from the adapter, just the constructor and the newView method.
public EmailViewCursorAdapter(Context context, Cursor c) {
super(context, c, true);
inflater = ((Activity) context).getLayoutInflater();
usernameInd = c.getColumnIndex("sender_username");
createdInd = c.getColumnIndex("created_at");
bodyInd = c.getColumnIndex("body");
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Log.i(TAG, "Made it here - new view");
View view = inflater.inflate(R.layout.email_view_item, parent, false);
TextView senderName = (TextView) view.findViewById(R.id.sender_username);
TextView timeString = (TextView) view.findViewById(R.id.sent_time);
TextView emailBody = (TextView) view.findViewById(R.id.email_body);
senderName.setText(cursor.getString(usernameInd));
if(senderName.getText().equals(DataManager.getUser().getUsername()))
senderName.setTextColor(0x999999);
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sent = format.parse(cursor.getString(createdInd));
timeString.setText(EmailModel.createTimeText(sent));
} catch (ParseException e) {
timeString.setText("");
}
emailBody.setText(cursor.getString(bodyInd));
return view;
}
source
share