'get position item from a multiple json array

Hi i'm beginner of android and I have a big problem. I have this JSON file:

{"People":
[{"boy":{"name":"Jack","id":"11"}},
{"girl":{"name":"Rose","id":"22"}]}

I do a RecyclerView with jack and rose item. When I click Jack I want to get position of jack item and get ID item. For Example, when I click Jack item, I want: "id:11" and "position of ID item is:1" I try:

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
....
@Override
    public void onClick(View view) {
 Log.d("main_activity", String.valueOf(getAdapterPosition()));
 listfragment.onclickviewHolder(view, getAdapterPosition());
}
}

public class Startfragment extends Fragment {
.......
public void onclickviewHolder(View v,int position){
      Log.d("main_activity_position",Model.getInstance().getPeople().get(position).getid());
        Bundle args=new Bundle();
        args.putString("id",Model.getInstance().getPeople().get(position).getid());
        Linedetailfragment l=new Linedetailfragment();
        getActivity().getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, l).addToBackStack(null).commit();
    }
}

When i click on jack item i don't have right position of element and i can't get id element. Why? How can i do it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source