-1

Good evening I am trying to make users can change font in other layout called row.XML from the main activity class everything seems okay but there's no change of the font or color it seems like look not linking Any idea guys Edit: I used include method row.XML in main XML but all in vain

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view;
    /* We inflate the xml which gives us a view */
    view = inflater.inflate(R.layout.row, null);

    /* Get the widget with id name which is defined in the xml of the row */
    textfont = (TextView) view.findViewById(R.id.textItemmain);

(https://i.stack.imgur.com/GN6UQ.png)

Hicham
  • 29
  • 4

2 Answers2

2

That is not how views work, views are not explicitly bound to an activity so all you are doing by inflating that view is inflating a view that isn't associated to anything.

To send data back to an activity you need to use startActivityForResult then listen for data coming back to it when the activity is resumed

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • In fact I am just beginner I am not expertise in java android so that I am finding difficult to understand what do you meant when you said startActivityForResult – Hicham Sep 29 '21 at 16:22
  • 1
    take a look at this https://stackoverflow.com/questions/920306/sending-data-back-to-the-main-activity-in-android – tyczj Sep 29 '21 at 16:26
  • Thank you very much for being patient with me but it looks not what I am looking for because I don't want to passe some strings from activity to another I just want to change the font family of textvew from currently class in other not running – Hicham Sep 29 '21 at 16:32
  • which I said you cannot do in the way you are doing, you need to send some data back to that activity to tell the activity that you need to change it. There is no direct communication between activities – tyczj Sep 29 '21 at 16:39
1

First of all you need to know that you can't change the views properties of another layout activity directly from your current activity it is not possible, what you can do is that before going to the next activity you can pass an intent with a Boolean flag that will be check in the targeted activity to see if a boolean condition is true or false if it is true change the font of textview in target activity if it is false dont do anything, This is the only way to achieve what you are trying to do. If you can't create an intent and pass boolean extra in it post in comments I'll update the answer.

MoonLight
  • 460
  • 4
  • 15
  • Thanks sir for helping, but in child XML I have no Java class it's just XML has one textview in it I am calling that textview from main activity to use it in listview in the main activity so I need to allow users can change font as they like – Hicham Sep 29 '21 at 23:30