我想继续在同一个地方观看我的物品,当我将新物品添加到列表中时,我该怎么办?当我添加一个新项目时,我该如何保存在我的listView项目中?
我正在使用firebase,但这不是问题所在。
在这里,我要的项目看
这里,发送我失望
//这样添加我的项目在新项目MainClass
if (o instanceof Post) {
posts.add((Post) o);
listaFeed.notifyDataSetChanged();
}
public class ListaFeed extends BaseAdapter {
private ArrayList<Post> posts;
private Context context;
public ListaFeed(ArrayList<Post> posts, Context context) {
this.posts = posts;
this.context = context;
}
@Override
public int getCount() {
return posts.size();
}
@Override
public Object getItem(int position) {
return posts.get(position-getCount()-1);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView==null){
convertView = LayoutInflater.from(this.context).inflate(R.layout.card_feed, null);}
Post post = (Post) getItem(position);
ImageView foto = convertView.findViewById(R.id.iv_foto);
TextView titulo = convertView.findViewById(R.id.tv_titulo);
TextView autor = convertView.findViewById(R.id.tv_autor);
TextView modo = convertView.findViewById(R.id.tv_modo);
Picasso.with(context).load(post.getFoto()).into(foto);
titulo.setText(post.getTitulo());
autor.setText(post.getAutor());
modo.setText(post.getModo());
return convertView;
}
}
在arraylist中的第0个位置添加新项目将解决这个 – Shruti