我有简单的适配器显示列表,在数组中有数据并将其加载到列表中并将此列表传递给适配器。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View rowView=convertView;
String[] data;
LayoutInflater inflater = context.getLayoutInflater();
if(rowView==null){
rowView = inflater.inflate(R.layout.list_inflator, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.dishName= (TextView)rowView.findViewById(R.id.textView1);
viewHolder.dishPrice = (TextView)rowView.findViewById(R.id.textView2);
viewHolder.add=(Button)rowView.findViewById(R.id.add);
rowView.setTag(viewHolder);
}
data=dishes.get(position).split("-");
Log.d("Data", data[0]+"///"+data[1]);
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.add.setTag(R.string.position,position);
if(data[0]!=null){
holder.dishName.setText(data[0]);
holder.add.setTag(R.string.dishname, data[0]);
}
if(data[1]!=null){
holder.dishPrice.setText(data[1]);
holder.add.setTag(R.string.dishprice, data[1]);
}
holder.add.setOnClickListener(context.addClick);
return rowView;
}