我有一個自定義列表視圖在android中,我設置了基本適配器,在自定義列表視圖的一行中,我有兩個texview。現在我從json解析中設置這兩個textviews的文本。我想顯示讀取未讀消息。我怎麼能做到這一點?如何在android中的自定義列表視圖中讀取未讀郵件
以下是我的適配器類代碼,
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
我怎樣才能文本顏色爲只讀未讀郵件。 任何幫助將不勝感激。
我希望這些消息是從數據庫中來,不是他們的價值? – Nizam
沒有數據通過json解析來自服務器。 –
在服務器端,有沒有數據庫來保存消息? – Nizam