0

我在android中有一个自定义列表视图,我在其中设置了基本适配器,在一排自定义列表视图中我有两个texview。现在我从 json 解析中设置这两个文本视图的文本。我想显示已读未读消息。我怎样才能做到这一点?

以下是我的适配器类代码,

public class ImageAdapter_Notification extends BaseAdapter
{


    //Serch
    Context mContext;
    LayoutInflater inflater;
    //Serch

    String[] message;
    String [] id;
    String[]date;

public ImageAdapter_Notification(Context context)
{
    mContext = context;
    inflater = LayoutInflater.from(mContext);
}

public ImageAdapter_Notification(Context context,String [] message, String [] id,String[]date)
{
    mContext = context;
    inflater = LayoutInflater.from(mContext); 
    this.message=message;
    this.id=id;
    this.date=date;

}



public class ViewHolder {
    TextView txt_top,txt_large,txt_date;

}

public int getCount() {
    //return array_str_logo.length;
    return message.length;


}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return position;
}

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

        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.custom_notification, null);

            // Locate the TextViews in listview_item.xml

            holder.txt_top = (TextView) convertView.findViewById(R.id.txt_top);
            holder.txt_large=(TextView) convertView.findViewById(R.id.txt_large);
            holder.txt_date=(TextView) convertView.findViewById(R.id.txt_date);

            // Locate the ImageView in listview_item.xml
            convertView.setTag(holder);
        }
        else {

            holder = (ViewHolder) convertView.getTag();
        }
        // Set the results into TextViews
    /*  if(position%2==0)
        {
        holder.txt_top.setTextColor(Color.RED);
        }else
        {


        }
    */  holder.txt_top.setText(id[position]);
        holder.txt_large.setText(message[position]);
        holder.txt_date.setText(date[position]);    



        convertView.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent intent=new Intent(Notification_Activity.this,Notification_Details.class);
                intent.putExtra("from", id[position]);
                intent.putExtra("message",  message[position].toString());
                intent.putExtra("date",  date[position].toString());
            //  Log.i("message", message[position].toString());
                startActivity(intent);


            }
        });



        return convertView;
    }


}// End of ImageAdapterclass

我怎样才能为已读未读消息添加文字颜色。任何帮助将不胜感激。

4

1 回答 1

0

如果您在服务器端有一个数据库来维护消息,那么为此添加一个额外的列将解决问题。说,专栏Status Integer Default 0

现在,在你的内部getView(),检查这个值并设置相应的颜色。

当用户阅读消息时,将表中的值更改为 1。

于 2013-10-10T11:13:59.437 回答