如何在android中自定义列表视图中读取未读消息

时间:2013-10-10 09:42:05

标签: android listview baseadapter

我在android中有一个自定义列表视图,其中我设置了基本适配器,在一行自定义列表视图中我有两个texview。现在我从json解析中设置这两个textviews的文本。我想显示读取未读消息。我怎么能实现这个目标?

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

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

如何为读取未读消息发送文本颜色。 任何帮助都会受到衷心的欢迎。

1 个答案:

答案 0 :(得分:0)

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

现在,在getView()内,检查此值并设置相应的颜色。

当用户阅读信息时,请将表格中的值更改为1.