D
D
Dauren S2016-10-05 10:42:51
Java
Dauren S, 2016-10-05 10:42:51

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;
    }
}

Attention to the question: How to pass to DetailActivity from which fragment the event was executed, since there are several fragments (tabs) OneFragment, TwoFragment and so on.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SofroN, 2016-10-05
@SofroN

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.putExtra
Get this data
Intent intent = getIntent();
    Bundle bundle = intent.getExtras();

    if(bundle != null){
        // здесь достаем из bundle данные
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question