我的目的是在这样的名单列表:
-alllist--------
----row---------
----row---------
-----(list)-----
-------textview
-------textview
---row---------
-----(list)----
.....
MainAdapter
类是工作的罚款与其他元素,但PlaceAdapter
仅将第一(或最后,我想不出)项的“嵌套”列表中。
问题是什么?
MainAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
PlaceHolder placeHolder = null;
if (convertView == null) {
placeHolder = new PlaceHolder();
convertView = mInflater.inflate(R.layout.convers_place, null);
placeHolder.listView = (ListView) convertView.findViewById(R.id.listView);
convertView.setTag(placeHolder);
} else {
placeHolder = (PlaceHolder)convertView.getTag();
}
PlaceAdapter adapter = new PlaceAdapter(ctx);
placeHolder.listView.setAdapter(adapter);
String arr[] = conversion.message.split(Pattern.quote("!!")); // Not empty
adapter.add(new PlaceModel(arr[0]));
adapter.add(new PlaceModel(arr[1]));
}
PlaceAdapter:
public class PlaceAdapter extends BaseAdapter {
Context ctx;
private List<PlaceModel> places = new ArrayList<>();
private LayoutInflater mInflater;
public PlaceAdapter(Context ctx){
this.ctx = ctx;
mInflater = (LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void add(PlaceModel object) {
this.places.add(object);
}
@Override
public int getCount() {
return this.places.size();
}
@Override
public PlaceModel getItem(int position) {
return this.places.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
PlaceHolder_ placeHolder = null;
PlaceModel place = getItem(position);
if (convertView == null) {
placeHolder = new PlaceHolder_();
convertView = mInflater.inflate(R.layout.convers_place_row, null);
placeHolder.name= (TextView)convertView.findViewById(R.id.row_name);
placeHolder.address= (TextView)convertView.findViewById(R.id.row_address);
placeHolder.map= (Button)convertView.findViewById(R.id.row_map);
convertView.setTag(placeHolder);
}
else {
placeHolder = (PlaceHolder_)convertView.getTag();
}
placeHolder.name.setText(place.getName());
placeHolder.address.setText(place.getAddress());
return convertView;
}
public static class PlaceHolder_ {
public TextView name;
public TextView address;
public Button map;
}
}
notifyDataSetChanged()
不会受到影响。