2011-02-14 7 views
3

맞춤 CursorAdapter를 사용하여 데이터베이스에서 ListView를 채우는 전자 메일 인터페이스를 만듭니다. 이 ListView의 항목은 전자 메일 스레드를 표시합니다. 전자 메일 스레드는 CursorAdapter를 사용하여 ListView를 매우 유사한 방식으로 채 웁니다. 내가 겪고있는 문제는 두 번째 ListView가 채워지지 않는다는 것입니다.Android CursorAdapter가 newView를 호출하지 않습니다.

이 두 어댑터를 모두 초기화하는 코드는 거의 동일하며 (모든 의도와 용도로 사용할 수 있습니다) 로그 문을 사용하여 커서가 두 번째 어댑터로 전달되는지 확인할 수있었습니다 비어 있지 않고 필요한 모든 데이터가 들어 있습니다. 문제는 newView 메서드가 호출되지 않는다는 것입니다. 나는 이것이 왜 일어나고 있는지 조사하려고 노력했지만 아무 것도 생각 나지 않았습니다. 내가 궁금해하는 이유는 newView 메소드가 호출되지 않는 이유이다. 이 전화는 어디에서 방아쇠를 당해야합니까?

다음은 ListActivity의 onCreate 메소드입니다.

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); 

} 

다음은 어댑터의 코드이며 생성자 및 newView 메소드입니다.

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; 
} 
+0

이 newView가 호출되지 정의 할 필요가 모든 행에 newView를 호출? CursorAdapter는 뷰를 재사용하므로 모든 행에 대해 호출되지 않습니다. bindView에 무엇이 있습니까? 로그에 오류가 있습니까? (BTW, TextView 값을 설정하는 코드를 bindView로 옮겨야합니다.) – Mike

+0

솔직히 말해서 bindView가 모든 작업을 수행하고 newView에서 호출하도록하고 있습니다. 질문을 명확하게 제시하기 위해 복사/붙여 넣기를했습니다. 나는 어느 것이 최선의 관행인지 확실하지 않았지만이 문제와 관련하여 차이를 만들지 않습니다. 질문에 답하기 위해 newView 시작 부분의 로그 문은 절대로 표시되지 않습니다. 나는 그것이 여러 커서가 열려있는 것과 관련이 있다는 것을 상상할 수 있지만 그 외에는 난처한 상황입니다. –

+0

오케이, 나 너무 어려워. 목록이 비어있을 때 (즉,'@ id/android : empty'를 ID로 사용하여'ListActivity' 레이아웃에서)보기를 추가하려고 시도한 적이 있습니까? 프레임 워크가 표시 할 항목이 목록에 있다고 생각하는지 여부를 알 수 있습니다. – Mike

답변

2

중위는

@Override 
public int getItemViewType(int position) { 

    } 
관련 문제