リストビューとカスタムアダプターに問題があります。私がそれをクリックすると消えていくボタンの可視性を入れようとしている私は、リストの編集と変更のための新しい要素を作成します。カスタムアダプターのボタンの表示の変更
しかし、動作しません。私はそれがnotifyOnDataChangeがボタンの可視性を再び見えるようにするためだと思います。
public class CustomAdapterIngredientsUser extends ArrayAdapter<Recipe.Ingredients.Ingredient>
List<Recipe.Ingredients.Ingredient> ingredientList;
Context context;
EditText textQuantity;
EditText textName;
Button xButton;
Button plusButton;
public CustomAdapterIngredientsUser(Context context, List<Recipe.Ingredients.Ingredient> resource) {
super(context,R.layout.ingredient_new_recipe,resource);
this.context = context;
this.ingredientList = resource;
}
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
final View customview = layoutInflater.inflate(R.layout.ingredient_new_recipe,parent,false);
textQuantity = (EditText) customview.findViewById(R.id.quantityText);
textName = (EditText) customview.findViewById(R.id.ingredientName);
plusButton= (Button) customview.findViewById(R.id.newIngredientButton);
xButton = (Button) customview.findViewById(R.id.Xbutton);
xButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ingredientList.remove(position);
notifyDataSetChanged();
}
});
plusButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plusButton.setVisibility(customview.GONE);
String name = textName.getText().toString();
String qnt = textQuantity.getText().toString();
Recipe.Ingredients.Ingredient ing2 = new Recipe.Ingredients.Ingredient("Quantity","Name","Photo");
ingredientList.add(ing2);
notifyDataSetChanged();
}
});
return customview;
}
これは、リストに新しい要素を追加してみましょう、と最初の1(プラスボタン)で、より多くのelemenetsを追加するためのボタンを削除する必要があります。ユーザーが成分のリストを作ることを可能にする。
コメントnotifyDataSetChange()行をチェックしてもう一度チェックします。 –