请看代码:
我在ListView上加载一个adapter,在这个adapter我绑定4个控件,分别显示图形和文字SimpleAdapter adapter=new SimpleAdapter(this,R.layout.accept_mms_item,cursor,
new String[]{"read","address","body","date"},new int[]{R.id.sms_imageView,R.id.phone_number_text,
R.id.mms_content_text,R.id.time_text});继承一个SimpleCursorAdapter类,重写bindView方法@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
LinearLayout layout;
super.bindView(view, context, cursor);
if(view!=null){
layout=(LinearLayout) view;
}
else{
Log.d(tag, "View is null");
layout=(LinearLayout)flater.inflate(R.layout.accept_mms_item, null);
}
String isReadStr=cursor.getString(cursor.getColumnIndex("read"));
String numStr=cursor.getString(cursor.getColumnIndex("address"));
String personStr=cursor.getString(cursor.getColumnIndex("person"));
String bodyStr=cursor.getString(cursor.getColumnIndex("body"));
String dateStr=cursor.getString(cursor.getColumnIndex("date"));
ImageView mmsImage=(ImageView)layout.findViewById(R.id.sms_imageView);
TextView numberText=(TextView)layout.findViewById(R.id.phone_number_text);
TextView bodyText=(TextView)layout.findViewById(R.id.mms_content_text);
TextView dateText=(TextView)layout.findViewById(R.id.time_text);
if(isReadStr=="0"){
//设置未读图片
Log.d(tag,"setting the un_read picture...");
mmsImage.setImageResource(R.drawable.book);
}
else{
//设置已读图片
Log.d(tag,"setting the read picture...");
mmsImage.setImageResource(R.drawable.read);
}运行以后,发现有设置ImageView控件的地方没有显示图片用log跟踪下,能运行到Log.d(tag,"setting the read picture...");
mmsImage.setImageResource(R.drawable.read);换其他的图片试了试,也没显示出来,然后查看了下xml文件:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget37"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RelativeLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/mms_content_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/phone_number_text"
android:layout_marginTop="2dip"
android:maxLines="1"
android:paddingRight="100px"
>
</TextView>
<TextView
android:id="@+id/phone_number_text"
android:layout_width="171px"
android:layout_height="24px"
android:text="TextView"
android:layout_alignTop="@+id/sms_imageView"
android:layout_toRightOf="@+id/sms_imageView"
>
</TextView>
<ImageView
android:id="@+id/sms_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/time_text"
android:layout_alignParentLeft="true"
>
</ImageView>
<TextView
android:id="@+id/time_text"
android:layout_width="97px"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
>
</TextView>
</RelativeLayout>
</LinearLayout>也没发现问题,请问各位大侠问题出在哪?
我在ListView上加载一个adapter,在这个adapter我绑定4个控件,分别显示图形和文字SimpleAdapter adapter=new SimpleAdapter(this,R.layout.accept_mms_item,cursor,
new String[]{"read","address","body","date"},new int[]{R.id.sms_imageView,R.id.phone_number_text,
R.id.mms_content_text,R.id.time_text});继承一个SimpleCursorAdapter类,重写bindView方法@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
LinearLayout layout;
super.bindView(view, context, cursor);
if(view!=null){
layout=(LinearLayout) view;
}
else{
Log.d(tag, "View is null");
layout=(LinearLayout)flater.inflate(R.layout.accept_mms_item, null);
}
String isReadStr=cursor.getString(cursor.getColumnIndex("read"));
String numStr=cursor.getString(cursor.getColumnIndex("address"));
String personStr=cursor.getString(cursor.getColumnIndex("person"));
String bodyStr=cursor.getString(cursor.getColumnIndex("body"));
String dateStr=cursor.getString(cursor.getColumnIndex("date"));
ImageView mmsImage=(ImageView)layout.findViewById(R.id.sms_imageView);
TextView numberText=(TextView)layout.findViewById(R.id.phone_number_text);
TextView bodyText=(TextView)layout.findViewById(R.id.mms_content_text);
TextView dateText=(TextView)layout.findViewById(R.id.time_text);
if(isReadStr=="0"){
//设置未读图片
Log.d(tag,"setting the un_read picture...");
mmsImage.setImageResource(R.drawable.book);
}
else{
//设置已读图片
Log.d(tag,"setting the read picture...");
mmsImage.setImageResource(R.drawable.read);
}运行以后,发现有设置ImageView控件的地方没有显示图片用log跟踪下,能运行到Log.d(tag,"setting the read picture...");
mmsImage.setImageResource(R.drawable.read);换其他的图片试了试,也没显示出来,然后查看了下xml文件:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget37"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RelativeLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/mms_content_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/phone_number_text"
android:layout_marginTop="2dip"
android:maxLines="1"
android:paddingRight="100px"
>
</TextView>
<TextView
android:id="@+id/phone_number_text"
android:layout_width="171px"
android:layout_height="24px"
android:text="TextView"
android:layout_alignTop="@+id/sms_imageView"
android:layout_toRightOf="@+id/sms_imageView"
>
</TextView>
<ImageView
android:id="@+id/sms_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/time_text"
android:layout_alignParentLeft="true"
>
</ImageView>
<TextView
android:id="@+id/time_text"
android:layout_width="97px"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
>
</TextView>
</RelativeLayout>
</LinearLayout>也没发现问题,请问各位大侠问题出在哪?
用baseadapter不方便点吗?