リストビュー行で複数の(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;
}
}