我想在列表视图行中使用多个(2)文本视图。我想我必须创建自定义适配器,但是有了这个适配器,我想在单击如下按钮时使用插入多个数据来定位 0:mAdapter.insert(mytext1, mytext2, 0);
但我无法通过示例适配器实现这一点:
public class Durations {
private String name;
private String address;
public Durations(String name, String address) {
this.name = name;
this.address = address;
}
public void setName(String name) {
this.name= name;
}
public String getName() {
return name;
}
public void setAddress(String address) {
this.address= address;
}
public String getAddress() {
return address;
}
}
public class CustomAdapter extends ArrayAdapter {
private final Activity activity;
private final List list;
public CustomAdapter(Activity activity, ArrayList<Durations> list) {
this.activity = activity;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
ViewHolder view;
if(rowView == null)
{
// Get a new instance of the row layout view
LayoutInflater inflater = activity.getLayoutInflater();
rowView = inflater.inflate(R.layout.row, null);
// Hold the view objects in an object, that way the don't need to be "re- finded"
view = new ViewHolder();
view.retaurant_name= (TextView) rowView.findViewById(R.id.text1);
view.restaurant_address= (TextView) rowView.findViewById(R.id.text2);
rowView.setTag(view);
} else {
view = (ViewHolder) rowView.getTag();
}
return rowView;
}
protected class ViewHolder{
protected TextView retaurant_name;
protected TextView restaurant_address;
}
}