我有一个ListView
,每个项目都有一个gridview
:
因此,当我按下添加按钮时,我需要向gridView
(scenesGridViewAdapter
)适配器添加一个新项目,但是当我按下添加按钮时,总会添加到最后一个gridview。
public class ScenesAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<SceneObject> sceneObjects;
private ArrayList<ScenesGridViewAdapter> scenesGridViewAdapters;
private ScenesGridViewAdapter scenesGridViewAdapter;
public ScenesAdapter(Activity activity, ArrayList<SceneObject> sceneObjects) {
this.activity = activity;
this.sceneObjects = sceneObjects;
this.scenesGridViewAdapters = new ArrayList<>();
}
@Override
public int getCount() {
return this.sceneObjects.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_scenes_item, null);
viewHolder = new ViewHolder();
viewHolder.tvStepIndex = (TextView) convertView.findViewById(R.id.tv_scene_index);
viewHolder.bmb1 = (BoomMenuButton) convertView.findViewById(R.id.bmb_open_item_menu);
viewHolder.scenesGridView = (ScenesGridView)convertView.findViewById(R.id.gv_scene_items) ;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
int index = position + 1;
viewHolder.tvStepIndex.setText("" + index);
scenesGridViewAdapter = new
ScenesGridViewAdapter(this.activity, sceneObjects.get(position).getScenes());
viewHolder.scenesGridView.setAdapter(scenesGridViewAdapter);
viewHolder.bmb1.clearBuilders();
viewHolder.bmb1.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilder("Añadir acción"));
viewHolder.bmb1.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilder("Eliminar paso"));
viewHolder.bmb1.setOnBoomListener(new OnBoomListener() {
@Override
public void onClicked(int index, BoomButton boomButton) {
switch (index){
case 0:
scenesGridViewAdapter.addNew("hello");
notifyDataSetChanged();
break;
case 1:
sceneObjects.remove(position);
notifyDataSetChanged();
break;
}
}
@Override
public void onBackgroundClick() {
}
@Override
public void onBoomWillHide() {
}
@Override
public void onBoomDidHide() {
}
@Override
public void onBoomWillShow() {
}
@Override
public void onBoomDidShow() {
}
});
return convertView;
}
class ViewHolder {
TextView tvStepIndex;
ScenesGridView scenesGridView;
BoomMenuButton bmb1;
}
public void addNewScene(SceneObject sceneObject){
sceneObjects.add(sceneObject);
this.notifyDataSetChanged();
}
}
您可以帮我添加并添加到gridview
位置吗?
谢谢。