【问题标题】:how to ser read unread message in custom listview in android如何在android的自定义列表视图中读取未读消息
【发布时间】:2013-10-10 09:42:04
【问题描述】:

我在 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

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

【问题讨论】:

  • 我希望这些消息来自数据库,不是吗?
  • 没有数据来自服务器通过json解析。
  • 在服务器端,是否有数据库来保存消息?
  • @Nizam...是的,有一个数据库可以保存消息

标签: android listview baseadapter


【解决方案1】:

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

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

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

【讨论】:

  • 您的意思是说,如果用户当时阅读了消息,android 应用程序应该发布一些更新数据库状态的内容?如果是这样,那么该消息也将自动考虑为其他用户的阅读。不是吗?
  • 所以消息不是针对特定用户的?
  • 没有。对于每个安装应用程序的用户
  • 那么你必须为此设计另一个表(带有外键)。对于每个用户,都应该有一个条目。
  • 谢谢,这对我有很大帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多