根据sqlite结果区分listview中的行

时间:2013-12-16 15:39:37

标签: android sqlite listview load populate

在我的项目中,我需要从webservice获取消息并在listview中查看。我需要区分listview中的读取和未读消息。我检索到消息并将其存储在sqlite数据库中。如何区分读取和未读取消息。而且listview也没有正确填充。而不是显示文本,它显示某行中的textview id。

这是我的代码,

      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>

0 个答案:

没有答案