2014-09-01 64 views
1

這裏我得到的控制檯數據打印數據列表視圖:如何在Android的

DataBaseManager dbManager = new DataBaseManager(context); 
ArrayList<Notify> notifies = dbManager.getNotificationList(); 
System.out.println("today " + notifies.size()); 
for (int i = 0; i < notifies.size(); i++) { 
    System.out 
     .println("Valueeeeeeeeeeeeeeeee:" 
       + notifies.get(i).getNotificationStatus() 
       + "\n" 
       + notifies.get(i).getNotificationServerId() + "\n" + 
       notifies.get(i).getNotificationDatetime()); 

} 

這裏是我的datamodelclass:

public class Notify { 
    private String notificationId; 
    private String notificationServerId; 
    private String notificationSenderID; 
    private String notificationRecieverID; 
    private String notificationType; 
    private String notificationDescrpiton; 
    private String notificationStatus; 
    private String notificationDatetime; 
    private String notificationIsRead; 

    public String getNotificationId() { 
     return notificationId; 
    } 

    public void setNotificationId(String notificationId) { 
     this.notificationId = notificationId; 
    } 

    public String getNotificationServerId() { 
     return notificationServerId; 
    } 

    public void setNotificationServerId(String notificationServerId) { 
     this.notificationServerId = notificationServerId; 
    } 

    public String getNotificationSenderID() { 
     return notificationSenderID; 
    } 

    public void setNotificationSenderID(String notificationSenderID) { 
     this.notificationSenderID = notificationSenderID; 
    } 

    public String getNotificationRecieverID() { 
     return notificationRecieverID; 
    } 

    public void setNotificationRecieverID(String notificationRecieverID) { 
     this.notificationRecieverID = notificationRecieverID; 
    } 

    public String getNotificationType() { 
     return notificationType; 
    } 

    public void setNotificationType(String notificationType) { 
     this.notificationType = notificationType; 
    } 

    public String getNotificationDescrpiton() { 
     return notificationDescrpiton; 
    } 

    public void setNotificationDescrpiton(String notificationDescrpiton) { 
     this.notificationDescrpiton = notificationDescrpiton; 
    } 

    public String getNotificationStatus() { 
     return notificationStatus; 
    } 

    public void setNotificationStatus(String notificationStatus) { 
     this.notificationStatus = notificationStatus; 
    } 

    public String getNotificationDatetime() { 
     return notificationDatetime; 
    } 

    public void setNotificationDatetime(String notificationDatetime) { 
     this.notificationDatetime = notificationDatetime; 
    } 

    public String getNotificationIsRead() { 
     return notificationIsRead; 
    } 

這裏是我的適配器:

public class RowItem extends BaseAdapter { 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public Object getItem(int arg0) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public long getItemId(int arg0) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public View getView(int arg0, View arg1, ViewGroup arg2) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

} 

我想tp打印值在列表中我有3個文本視圖

notifies.get(i).getNotificationStatus() 
notifies.get(i).getNotificationStatus() 
notifies.get(i).getNotificationStatus() 

但我無法打印數據,請幫助如何設置適配器的值。

+0

你在DataBase類中設置了你的數據?你必須通過''通知'arraylist到'RowItem'適配器和'getView()'方法來獲取你的值。 – Piyush 2014-09-01 07:55:18

+0

是的,我正在獲取日誌中的數據 – Edge 2014-09-01 08:26:04

+0

因此請按照我的意見 – Piyush 2014-09-01 09:03:42

回答

0

當你發送ArrayList同時創造對象Notifcationadapter(內部活動或片段)的沒有必要Notifcationadapter填寫數據。您應該只聲​​明數組列表ArrayList<Notify> notifies;

代碼

Context context; 
ViewHolder holder; 
//LinearLayout linear2; 
ArrayList<Notify> notifies; 
public Notifcationadapter(Context context,ArrayList<Notify> notifies) { 
    super(); 
    this.context = context; 
    this.notifies = notifies; 
} 
+0

http://pastie.org/9518787 – Edge 2014-09-01 10:36:43

+0

好吧等待讓我試試 – Edge 2014-09-01 10:41:17

0

可以使用ViewHolder類爲該

+1

這必須是評論! – Piyush 2014-09-01 09:33:32

+0

http://pastie.org/9518714嘗試此代碼,但NullPointerException得到 – Edge 2014-09-01 09:57:22

+0

@PG_Android告訴解決方案 – Edge 2014-09-01 09:58:07

0

爲什麼要退0到getCount將(); 修復你的適配器 -

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return notifies.size(); 
} 

@Override 
    public Object getItem(int arg0) { 
     // TODO Auto-generated method stub 
     return notifies.get(arg0); 
    } 

@Override 
public long getItemId(int arg0) { 
    // TODO Auto-generated method stub 
    return arg0; 
}