在滚动ListView上,我的活动停止了

时间:2015-09-21 08:27:36

标签: android listview

我有一个arrayadapter如下:

public class SmsArrayAdapter extends ArrayAdapter<String> {

    List<String> smsBody;
    List<Boolean> Status;
    List<String> time;
    List<String> SmsMessageId;

    Context context;
    private static LayoutInflater inflater = null;
    String fromNumber;

    public SmsArrayAdapter(Context context, int resource, List<String> smsBody,
            List<Boolean> Status, List<String> time, List<String> SmsMessageId,
            String fromNumber) {
        super(context, resource, smsBody);
        this.smsBody = smsBody;
        this.Status = Status;
        this.context = context;
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.fromNumber = fromNumber;
        this.time = time;
        this.SmsMessageId=SmsMessageId;
    }

    public String getStr(int position) {
        return smsBody.get(position);
    }
    public String getId(int position)
    {
        return SmsMessageId.get(position);
    }
    public void setRead(int position,String smsMessageId)
    {
        Status.set(position, true);
        ContentValues values = new ContentValues();
        values.put("read", true);
        context.getContentResolver().update(Uri.parse("content://sms/inbox"), values, "_id=" +smsMessageId, null);
    }
    @Override
    public String getItem(int position) {
        // TODO Auto-generated method stub
        return smsBody.get(position);
    }

    public static class ViewHolder {

        public TextView textfrom;
        public TextView text_sms;
        public TextView text_time;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {

            /****** Inflate tabitem.xml file for each row ( Defined below ) *******/
            convertView = inflater.inflate(R.layout.row_item, null);

            /****** View Holder Object to contain tabitem.xml file elements ******/

            holder = new ViewHolder();

            holder.textfrom = (TextView) convertView
                    .findViewById(R.id.textView_from);
            holder.text_sms = (TextView) convertView
                    .findViewById(R.id.textView_sms);
            holder.text_time = (TextView) convertView
                    .findViewById(R.id.textView_time);

            /************ Set holder with LayoutInflater ************/
            convertView.setTag(holder);
        } else
            holder = (ViewHolder) convertView.getTag();


        holder.textfrom.setText(" " + fromNumber);

        String smsTextToDisplay = smsBody.get(position);
        if (smsTextToDisplay.length() > 100)
            smsTextToDisplay = smsTextToDisplay.substring(0, 99) + " ...";

        holder.text_sms.setText(smsTextToDisplay);


        holder.text_time.setText(time.get(position));
        if (Status.get(position) == false) {
            convertView.setBackgroundColor(context.getResources().getColor(
                    R.color.light_blue_overlay));

        }
        return convertView;
    }

}

在滚动此适配器的列表视图时,我的活动将停止。我怎样才能避免这个错误?错误在哪里?

0 个答案:

没有答案