0
在我的項目中,我需要從webservice和視圖中獲取消息,在listview.I需要區分listview.I中讀取和未讀消息檢索到的消息,並將其存儲在sqlite數據庫中。如何區分讀取和未讀的消息。而且listview沒有正確填充。不是顯示文本,而是顯示textview id在某一行。根據sqlite結果在列表視圖中區分行
這裏是我的代碼,
public class Message_Adapter extends ArrayAdapter<Message> implements OnClickListener {
Activity activity;
int layoutResourceId;
Message user;
ArrayList<Message> data = new ArrayList<Message>();
public Message_Adapter(Activity act, int layoutResourceId,
List<Message> data) {
super(act, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.activity = act;
this.data = (ArrayList<Message>) data;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
UserHolder holder = null;
if (row == null) {
LayoutInflater inflater = LayoutInflater.from(activity);
row = inflater.inflate(layoutResourceId, parent, false);
holder = new UserHolder();
holder.fromnum = (TextView) row.findViewById(R.id.fromno);
holder.tonum = (TextView) row.findViewById(R.id.tonum);
holder.body= (TextView) row.findViewById(R.id.msgbody);
holder.date = (TextView) row.findViewById(R.id.msgdate);
holder.delete = (Button) row.findViewById(R.id.btn_delete);
holder.status = (TextView) row.findViewById(R.id.staty);
row.setTag(holder);
} else {
holder = (UserHolder) row.getTag();
}
user = data.get(position);
smsm=user.getID();
System.out.println("Smsm::::"+smsm);
holder.delete.setTag(user.getID());
holder.fromnum.setText(user.getmsgfrom());
holder.tonum.setText(user.getto());
holder.body.setText(user.getmsg());
holder.date.setText(user.getdate());
holder.status.setText(user.getstatus());
holder.delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
// TODO Auto-generated method stub
// show a message while loader is loading
AlertDialog.Builder adb = new AlertDialog.Builder(activity);
adb.setTitle("Delete?");
adb.setMessage("Are you sure you want to delete ");
//final int user_id = Integer.parseInt(v.getTag().toString());
adb.setNegativeButton("Cancel", null);
adb.setPositiveButton("Ok",
new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// MyDataObject.remove(positionToRemove);
DatabaseHandler dBHandler = new DatabaseHandler(
activity.getApplicationContext());
dBHandler.Delete_Contact(smsm);
InboxActivity.this.onResume();
}
});
adb.show();
}
});
row.setOnClickListener(new OnItemClickListener(position));
return row;
}
這是我的收件箱中的自定義佈局,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100sp"
android:background="@drawable/edittext"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/fromno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tonum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/msgbody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/msgdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/staty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
你用哪個變量從數據庫中讀取和未讀郵件進行區分? 你可以把你看到的錯誤人口的圖片放在一起嗎? –
我有名爲Status.For那些有0值的行必須不同於具有1值的行... – Jolly
@Lena Bru,我無法上傳屏幕截圖...不是加載textview的詳細信息,而是加載資源ID這些textviews文字 – Jolly