该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我给ListView使用BaseAdapter适配器,却只显示第一项的文字,而图片却都显示了,好奇怪。(编译无问题)
BaseAdapter代码如下:
BaseAdapter ba =new BaseAdapter(){
@Override
public int getCount()
{
// TODO: Implement this method
return titles.length;
}
@Override
public View getView(int p1, View v, ViewGroup p3)
{
// TODO: Implement this method
if(v==null){
v=inflater.inflate(R.layout.title,null);
}
else{
ImageView image=(ImageView)v.findViewById(R.id.imageview);
TextView stitle=(TextView)v.findViewById(R.id.stitle);
TextView stext=(TextView)v.findViewById(R.id.stext);
image.setImageResource(R.drawable.information);
stitle.setText(titles[p1]);
stitle.setTextSize((int)res.getDimension(R.dimen.size_medium));
stext.setTextSize((int)res.getDimension(R.dimen.size_small));
boolean isReadOK=sp.getBoolean((number<10)?
number+"0"+p1 : number+""+p1
,false);
stext.setText(isReadOK==true ? "阅读完毕!":"");v.setBackgroundResource(R.drawable.button);
}
return v;
}
@Override
public Object getItem(int p1)
{
// TODO: Implement this method
return titles[p1];
}
@Override
public long getItemId(int p1)
{
// TODO: Implement this method
return p1;
}
};
title.xml的代码如下:
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left|center">
android:layout_height="50dp"
android:layout_width="50dp"
android:src="@drawable/information"
android:id="@+id/imageview"
android:layout_marginLeft="10dp"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="left"
android:layout_centerInParent="true"
android:id="@+id/stitle"
android:layout_toRightOf="@id/imageview"/>
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:id="@+id/stext"
android:textColor="#FF0000"
android:layout_alignParentRight="true"
android:gravity="right"/>
希望得到解答。