我有一个ListActivity
,我需要在每一行中显示一个图像和文本。
event.xml
布局如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:layout_height="wrap_content"
android:layout_width="30px"
android:layout_marginTop="2px" android:layout_marginRight="2px"
android:layout_marginLeft="2px" android:id="@+id/logoImage">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/title"
android:textSize="15px"></TextView>
</LinearLayout>
活动如下所示:
public class Activity extends ListActivity{
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
dba=new DatabaseAdapter(this);
dba.open();
View header = getLayoutInflater().inflate(R.layout.header, null);
ListView lv = getListView();
lv.addHeaderView(header);
fillOnStart();
}
private void fillOnStart(){
ArrayList<Title> temp = dba.returnTitle(); // this works
ArrAdapter notes = new ArrAdapter(this, temp);
Toast.makeText(this, "Size: " +notes.getCount(), Toast.LENGTH_LONG).show();
//because this show good size
setListAdapter(notes);
}
我的适配器看起来像这样:
private class ArrAdapter extends BaseAdapter{
private Context mContext;
private ArrayList<Title> lista;
public ArrAdapter(Context c, ArrayList<Title> list){
mContext = c;
this.lista =list;
}
public int getCount() {
// TODO Auto-generated method stub
return lista.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder vh =null;
Title title= lista.get(position);
LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.event, parent, false);
ImageView imlogo = (ImageView)v.findViewById(R.id.logoImage);
TextView textTitle = (TextView)v.findViewById(R.id.title);
imlogo.setImageResource(title.getLogo());
textTitle.setText(title.getTit());
return v;
}
}
类标题看起来像:
public class Title {
public int id;
public String tit;
public Bitmap logo;
public Bitmap getLogo() {
return logo;
}
... and other setter and getter
}
并且方法返回 Arraylist(在 dba 中),标题如下所示:
public ArrayList<Title> returnTitle(){
Title t = new Title(1,"aaaaaaaaaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\favicon.ico"));
Title t1 = new Title(2,"assdsdsdsdaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\icon.ico"));
ArrayList<Title> art = new ArrayList<Title>(2);
art.add(t);
art.add(t1);
return art;
}
我的列表活动只显示文本。我必须改变什么才能看到带文字的图像?