我不確定這是不是你正在尋找,但你可以嘗試這樣的事情。
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
setListAdapter(new CustomAdapter(this));
selection=(TextView)findViewById(R.id.selection);
}
class CustomAdapter extends ArrayAdapter {
Activity context;
CustomAdapter(Activity context) {
super(context, R.layout.row, items);
this.context=context;
}
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
if (row==null) {
LayoutInflater inflater=context.getLayoutInflater();
row=inflater.inflate(R.layout.row, null);
}
TextView label=(TextView)row.findViewById(R.id.label);
label.setText(items[position]);
ImageView icon=(ImageView)row.findViewById(R.id.icon);
//you can put your own logic to add images here
if (items[position].length()>4) {
icon.setImageResource(R.drawable.delete);
}
else {
icon.setImageResource(R.drawable.ok);
}
return(row);
}
}
想要嘗試做的是將圖像添加到每一行。那麼我需要什麼?欣賞它。 – danish 2011-01-08 01:02:52