mardi 4 août 2015

RecyclerView.Adapter get item position of my list

I have created a RecyclerView.Adapter and I want to fill a list.. so my problem now is I don't know how to implement the get position of my list.

below you can see my code:

public class RecyclerViewAdapter extends RecyclerView.Adapter {

List<Result> _contents;

public RecyclerViewAdapter(List<Result> contents) {
    this._contents = contents;
}


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

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
    View view = null;
    view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.list_item_card_small, parent, false);

    Result tempResult = _contents.get(position);

    TextView temp = (TextView) view.findViewById(R.id.text_city_name);
    temp.setText(tempResult.getInfo().getCity().getName());

    return new RecyclerView.ViewHolder(view) {
    };
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

   }
}

so the function onCreateViewHolder doesn't get properly the id is always the same id.. how can I fix this or implement to get the right position of mi list?¿ What it´s happening now is the list has the right number of items but is always the same item, the fist one. I guess it´s something simple but I cant figure out how to implement it.

Thanks!!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire