Greetings, I tried to implement the settings, the hierarchy was great.

I have a TextView in the main one, in this one I call a DialogFragment , the DialogFragment contains a RecyclerView which displays a list of settings through its adapter. In this adapter, I implemented an onClick method in which I call AlertDialog :

  viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { AlertDialog.Builder alt_bld = new AlertDialog.Builder(view.getContext()); 

It turned out like this: MainActivity/DialogFragment/RecyclerViewAdapter/AlertDialog

Question: How can I change from my AlertDialog a, for example, the size of my TextView in the main activation?

    1 answer 1

    There is a standard pattern of fragment interaction with an Activity or other fragments.

    It is that the fragment must declare an interface that is implemented by those who want to interact with the fragment, such as:

     public class MyFragment extends Fragment { //blah-blah public interface MyFragmentListener { public void onFragmentSomethingHappens(); public void onFragmentYetAnotherHappens(); } } 

    In an Activity or other snippet, do so.

     public class MyActivity extends Activity implements MyFragment.MyFragmentListener { //blah-blah public void onFragmentSomethingHappens() { //blah-blah } } 

    Actually everything. When you create an adapter, get a link to the fragment, it is quite simple, then we call the fragment interface method, on which something happens in the Activity - in your case, changing the size of TextView

    • Could you explain in more detail, using simple names as an example, where to get the link to the fragment, where to call the method. The head does not cook at all, like a short and clear answer, I can not figure it out. - McDaggen
    • @McDaggen I have my own policy regarding answers - I always give not answers, but directions for work. Copy-peist is not for me - it is for Google. - Barmaley