当然可以,但是您首先需要创建一个扩展 ArrayAdapter<> 的类
这个类可能是这样的:
public class Mylistcustom extends ArrayAdapter<String> {
private LayoutInflater mInflater;
private int mViewResourceId;
private String[] your_date;
public Mylistcustom(Context ctx, int viewResourceId, String[] data) {
super(ctx, viewResourceId,data);
this.contexto=ctx;
mInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mViewResourceId = viewResourceId;
this.your_data=data;
@Override
public int getCount() {
return your_data.length;
}
@Override
public String getItem(int position) {
return your_data[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
rowView = mInflater.inflate(mViewResourceId, null);// you are inflating your xml layout
text=(textView) rowView.findViewById(R.id.textView);//find a textview in your layout, of course you can add whatever you want such as ImaveView Buttons ....
text.setText(your_data[position]); // and set text from your_data
return rowView;
} }
在列表视图活动中,您只需调用构造函数并传递您的数据、布局和上下文
Myadapter = new Mylistcustom(context, R.layout.YOUR_XML_LAYOUT,DATA);
// and finally set the adapter to your list
ListView lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(Myadapter);