Home > Enterprise >  findViewById from specific layout seems not linked
findViewById from specific layout seems not linked

Time:09-30

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)

CodePudding user response:

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

CodePudding user response:

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.

  • Related