RecylcerView首先显示数组的所有项目,但之后它只显示第一项

时间:2016-07-07 07:42:11

标签: android android-recyclerview

我正在显示一个数组的内容但它只显示所有项目,每当我在代码中更改某些东西后,它只显示arrray的第一项。 我正在使用API​​级别24和构建工具版本24

public class AccountAdapter extends RecyclerView.Adapter<AccountAdapter.AccountHolder> {


    ArrayList<String> accountDetail;


    public AccountAdapter(ArrayList<String> accountDetail, Context context){
        this.accountDetail=accountDetail;          

    }

        @Override
        public AccountAdapter.AccountHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.account_row,parent,false);
        AccountHolder accountHolder=new AccountHolder(view);

        return accountHolder;
    }

    @Override
    public void onBindViewHolder(AccountAdapter.AccountHolder holder, int position) {
    final String details = accountDetail.get(position);
    holder.textView.setText(accountDetail.get(position).toString());

    }

    @Override
    public int getItemCount() {
    return accountDetail.size();
    }

    public class AccountHolder extends RecyclerView.ViewHolder{
        protected TextView textView;
        public AccountHolder(View itemView) {
        super(itemView);
        textView=(TextView)itemView.findViewById(R.id.account_tv_row);
        }
    }
}

编辑: 这就是我如何调用适配器

        stringList= Arrays.asList(getResources().getStringArray(R.array.account));   
        account=new ArrayList<>(stringList);     
        recyclerView=(RecyclerView) view.findViewById(R.id.frag_account_rv);
        layoutManager=new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);
        adapter=new AccountAdapter(account,getContext());
        recyclerView.setAdapter(adapter);

0 个答案:

没有答案