I have the current onBindViewHolder
function:
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
myHolder = holder;
//Here I need to set text ("Hello" and "World") to myHolder.itemTextView.setText(text);
}
Assuming my dataset is a HashMap called myDataset
: If I have the position
, how do I get the key and value?
This is how I first set the data in the activity:
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
myDataset = new HashMap<>();
myDataset.put("key1", "Hello");
myDataset.put("key2", "World");
mAdapter = new HashMapAdapter(myDataset);
mRecyclerView.setAdapter(mAdapter);
Or, if I'm using HashMap, there should be a different way that's not based on position?