使用自定义适配器动画后删除项目

时间:2017-06-19 19:24:25

标签: android arrays listview adapter

我有一个自定义ListView和适配器。我尝试使用自定义适配器在幻灯片动画后删除ListView中的项目。但它总是给我一个"无法解决方法"删除""和"不兼容的类型" "中的错误配方项= adapter.getItem(position);"

  public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mListView = (ListView) findViewById(R.id.recipe_list_view);
    final ArrayList<Recipe> recipeList = Recipe.getRecipesFromFile("recipes.json", this);
     final Animation anim = AnimationUtils.loadAnimation(this, R.anim.fade_anim);
    String[] listItems = new String[recipeList.size()];
    for(int i = 0; i < recipeList.size(); i++){
      Recipe recipe = recipeList.get(i);
      listItems[i] = recipe.title;
    }
      final RecipeAdapter adapter = new RecipeAdapter(this, recipeList);
      mListView.setAdapter(adapter);
      final Context context = this;
      mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView parent, View view, final int position, long id) {
                      anim.setAnimationListener(new Animation.AnimationListener() {
                          @Override
                          public void onAnimationStart(Animation animation) {
                          }
                          @Override
                          public void onAnimationRepeat(Animation animation) {}
                          @Override
                          public void onAnimationEnd(Animation animation) {
                              Recipe item = adapter.getItem(position);
                              adapter.remove(item);
                                                        }
                      });
                      view.startAnimation(anim);
                  }
              });
              };
  private ListView mListView;
}

0 个答案:

没有答案