开发者

Android CursorAdapter not calling newView

开发者 https://www.devze.com 2023-02-10 15:48 出处:网络
I\'m creating an email interface that populates a ListView from a database using a custom CursorAdapter. The items in this ListView then display an email thread, which in very similar fashion populate

I'm creating an email interface that populates a ListView from a database using a custom CursorAdapter. The items in this ListView then display an email thread, which in very similar fashion populates a ListView using a CursorAdapter. The problem that I am having is that the second ListView will not populate.

The code for initializing both of these adapters is nearly identical (we can say they are for all intents and purposes) and through the use of log statements, I have been able to verify that the cursor being passed to the second adapter is not empty and contains all of the data that it should. What seems to be the problem is that the newView method is never called. I've tried to investigate why this is happening and have come up with nothing. What I'm wondering is why the newView method would not be called. Where is this call supposed to be triggered from?

Here is the onCreate method for the 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 newView method.

public EmailViewCursorAdapter(Context context, Cursor c) {
    super(context, c, true);
    inflater = ((Activity) context).getLayoutInflater();
    user开发者_运维知识库nameInd = 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;
}


inorder to call newView in every row you have to define

    @Override
public int getItemViewType(int position) {

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消