ListView第二次没有正确填充

时间:2013-12-19 05:35:21

标签: android-listview textview android-sqlite android-resources listitem

我已经实现了从sqlite数据库填充短信的自定义列表视图。所有行都填充到自定义列表视图中。当我单击列表行时,它将导航到该短信的详细视图,其中我传递的消息ID为那行。它将从sqlite数据库获取与该消息id相对应的详细信息。当我再次返回列表视图时,所选行已更改为消息内容的各个文本视图的资源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());



            row.setOnClickListener(new OnItemClickListener(position));

            return row;

        }

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }

         private class OnItemClickListener  implements OnClickListener{           
             private int mPosition;

             OnItemClickListener(int position){
                  mPosition = position;
             }

             @Override
             public void onClick(View arg0) {


              InboxActivity sct = (InboxActivity)activity;


                 sct.onItemClick(mPosition);
             }      

我不知道出了什么问题。请问有人可以帮我解决这个问题吗?

感谢!!!

0 个答案:

没有答案