I'm trying to get some data from my adapter with out success. I have in my main activity function that get some item position and need to get from this item the item name. I can figure out how to achieve that. I would be happy if someone can help me to fix it.
Function from my main activity -
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
if (direction == ItemTouchHelper.LEFT) {
Log.e(TAG, RecyclerAdapter.getIdFromPosition(position)); // Here what I try to do but to achieve that the getIdFromPosition
function need to be static and I can do this function to be static
} else {
Log.e(TAG,"Right");
}
}
The adapter function -
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
List<Task> data= Collections.emptyList();
public RecyclerAdapter(MainActivity mainActivity, List<Task> data) {
this.data = data;
}
@Override
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_list, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Task current = data.get(position);
//holder.tv1.setText(name[position]);
ViewHolder.tv2.setText(current.data);
if(current.sync != "null"){
holder.tv1.setText("A");
}
holder.imageView.setTag(holder);
}
@Override
public int getItemCount() {
return data.size();
}
public void getIdFromPosition(int position){
Log.e(TAG, data.get(position).getId());
}
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView tv1;
public static TextView tv2;
public ImageView imageView;
public ViewHolder(View view) {
super(view);
tv1 = (TextView) view.findViewById(R.id.list_title);
tv2 = (TextView)view.findViewById(R.id.list_desc);
imageView = (ImageView) view.findViewById(R.id.list_avatar);
view.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
//Log.e("test","test");
}
});
}
}