0

I need to edit an xml file, the problem is that I have multiple xmls and in all my classes/activities I can't put the xml as the main View.

So I must acces an xml file without setting it as main view on any activity.Is that even possible?

I mean I can make: View j = (View) findViewById(R.layout.mytest);

But how can I edit a button's text for ex in that mytest.xml file?

me_and
  • 15,158
  • 7
  • 59
  • 96
Milky Way
  • 287
  • 1
  • 3
  • 13
  • I am not sure if I understand the question correctly. But maybe [LayoutInfater](http://developer.android.com/reference/android/view/LayoutInflater.html) is what you are looking for. Take a look at this [SO question](http://stackoverflow.com/questions/3477422/layout-inflater-in-android). – Piotr Nov 20 '11 at 15:13

2 Answers2

0

although you can inflate any layout using LayoutInflator and make any changes for that instance in it , but you can not look for a persistent change in layout . so first setContentView , then change for that view only .

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
0

So you're saying you want to dynamically edit a layout xml file??? Example, you have a layout like...

<LinearLayout>
    ...
    <Button
        android:id="@+id/myButton"
        ...
        android:text="Some text" />
</LinearLayout>

...and you want to dynamically edit android:text="Some text" at run time???

If so, that isn't the way to do it. Simply leave the android:text attribute out of the layout xml and just set the text of the button at runtime.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContenView(R.layout.mytest);

    Button btn = (Button) findViewById(R.id.myButton);
    btn.setText("Whatever");
}
Squonk
  • 48,735
  • 19
  • 103
  • 135