notifyDataSetChanged()メソッドに関する多くの質問と回答が既にstackoverflowにあると認識していますが、それらのほとんどを見直して何が間違っているのか理解できませんここに。ユーザーが「Add Ingredient Button」をクリックすると、リストビューを動的に追加するようにしています。最初のクリック後に最初の成分が追加されますが、それ以降のクリックでもリストビューは変更されません。どんな助けもありがとうございます。私のリストビューを更新するためのnotifyDataSetChanged()の問題
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_recipe);
ButterKnife.bind(this);
mAddInstructionsButton.setOnClickListener(this);
mAddIngredientButton.setOnClickListener(this);
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, ingredientList);
mListView.setAdapter(adapter);
}
public void onClick(View v) {
if(v == mAddIngredientButton) {
if(mIngredientName.getText().toString().trim().equalsIgnoreCase("") || mIngredientMeasurement.getSelectedItem().toString().trim().equalsIgnoreCase("") || mIngredientCount.getText().toString().trim().equalsIgnoreCase("")) {
Toast answerStatus = Toast.makeText(NewRecipeActivity.this, "Fill out all fields", Toast.LENGTH_LONG);
answerStatus.show();
} else {
String ingredient = createIngredientString();
ingredientList.add(ingredient);
adapter.notifyDataSetChanged();
clearIngredientInputs();
Log.i("NewRecipeActivity", "List includes: " + ingredientList);
}
}
エラーを表示してください。 – KeLiuyue
エラーはありません。 Logcatは現在、私のingredientsListListArrayが確実に追加されていることを示しています:21476-21476/com.epicodus.myrestaurants I/NewRecipeActivity:リストには以下が含まれます:[3 tsp dsf] 10-14 01:46:00.804 21476-21476/com .epicodus.myrestaurants I/NewRecipeActivity:リストには以下が含まれます:[3 tsp dsf、4 tsp fdg] 10-14 02:08:25.729 21476-21476/com.epicodus.myrestaurants I/NewRecipeActivity:リストには以下が含まれます:[3 tsp dsf、 4 tsp fdg、4 tsp gdfg、4 tsp gdfg] 10-14 02:08:31.449 21476-21476/com.epicodus.myrestaurants I/NewRecipeActivity:リストには以下が含まれます:[3 tsp dsf、4 tsp fdg、4 tsp gdfg、6 tsp dsf] –
[https://stackoverflow.com/questions/3669325/notifydatasetchanged-example](https://stackoverflow.com/questions/3669325/notifydatasetchanged-example) – KeLiuyue