Answer the question
In order to leave comments, you need to log in
Pass to DetailActivity from which fragment the event was executed?
public class OneFragment extends Fragment {
public RecyclerView rv;
public Activity act;
public OneAdapter adapter;
public static UserModel usr;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_one, container, false);
// Replace 'android.R.id.list' with the 'id' of your RecyclerView
rv = (RecyclerView) view.findViewById(R.id.recyclerview);
rv.setHasFixedSize(true);
rv.setAdapter(adapter);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
rv.setLayoutManager(llm);
/* FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new JSONDownloader(MainActivity.this,jsonURL, rv).execute();
}
});*/
new JSONDownloader(act,jsonURL, rv,adapter).execute();
// new JSONTask();
rv.addOnItemTouchListener(
new RecyclerItemClickListener(getActivity(), rv ,new RecyclerItemClickListener.OnItemClickListener() {
@Override public void onItemClick(View view, int position) {
// do whatever
usr = adapter.getItem(position);
Context context=view.getContext();
Intent intent = new Intent(context, DetailActivity.class);
context.startActivity(intent);
}
@Override public void onLongItemClick(View view, int position) {
// do whatever
}
})
);
return view;
}
}
Answer the question
In order to leave comments, you need to log in
In this code add
new RecyclerItemClickListener(getActivity(), rv ,new RecyclerItemClickListener.OnItemClickListener() {
@Override public void onItemClick(View view, int position) {
// do whatever
usr = adapter.getItem(position);
Context context=view.getContext();
Intent intent = new Intent(context, DetailActivity.class);
context.startActivity(intent);
}
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if(bundle != null){
// здесь достаем из bundle данные
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question