views:

46

answers:

2

Hello guy's, i'm new at Android world, and i have a doubt, is there any method that give me the name of the id's i create in main.xml? For example i have this:

main.xml

<TextView android:id="@+id/text1"
       android:layout_width="70px"
       android:layout_height="70px"
       android:text="Google"
       />

<TextView android:id="@+id/text2"
       android:layout_width="70px"
       android:layout_height="70px"
       android:text="As"
       />

And what i want is the id name from the two TextView, is there any method that i can use in my class .java that give me for this example the id? In this case i want the (text1 and text2).

Thanks and forgive mi English.

A: 

inflate the file

linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View main = linflater.inflate(R.layout.main, null);

then run findViewById to turn TextView into an object

TextView text1 = (TextView)main.findViewById(R.id.text1);

then you can work with object text1 later like this

text1.setText("foo");
Pentium10
Hi,thank you.but what i want is more dynamic,i know that if i know the name of id i can get using this:TextView text1 = (TextView)findViewById(R.id.text1);but imagine that i don't know the name off the id, and what i want if there is any method that give me all the names of the ids that i have in the main.xml. and then create the object, one thing gone be static is that all gone be TextView.I want this, for example:name_offids = methodgivemeallidsname;and then create the objetsTextView text1 = (TextView)findViewById(R.id.name_offids);is any method that give me the name of ids?thanks
sgiro
+3  A: 

Set an id to the parent layout and try something like this:

    LinearLayout ll = findViewById(R.id.yourLayout);
    for(int i=0; i<ll.getChildCount(); i++){
        View v = ll.getChildAt(i);
        int idView = v.getId();
            //Do something with idView
    }
YaW
Thank you is something like that what i want.
sgiro