an abstract in my mind is something like
idontknow x = (idontknow) findViewById(R.string.stringname);
so that whenever i change x the R.string.stringname would also change
and thus i can use the R.string.stringname anywhere in the same project
but obviously it is an error
edit:
i would like to input my name(R.string.name or global) and age(R.string.age or global) on an EditText field on a formActivity
and in another differentActivity i would like to have this:
TextView x = (TextView) findViewById(<some id>);
x.setText("Hello "+ getString(R.string.nfoname)+ "you are"+getString(R.string.nfoname)+"years old");
This really seems like poor design. What are you doing that you don’t know the type of x, and it’s something that you need to persist across your application?
Everything that gets returned by findViewById() is a View object or one of its subclasses. So, right off the bat you know you have a view object. Another thing is that findViewById doesn’t accept a String as a parameter, it only accept an int value, such that R.id.myVar is actually an integer corresponding to a View in the inflated hierarchy.
If you absolutely have to do something like that, why wouldn’t you just use a common id value so that you’re always searching for the same id and assign it to a generic View object that can be compared using instanceof later? Like this:
In that case, your ID could be a constant that couldn’t be changed, and you always can figure out what subclass of View you’re dealing with. This feels like a more maintainable design than having global variables floating around, in my opinion