Soheil
Soheil

Reputation: 1706

how to access to widgets of a View in Android?

I'm making a View by inflating an xml layout:

    LayoutInflater inflater = (LayoutInflater) getBaseContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(com.example.R.layout.aaa, null);

in aaa.xml I have a RelativeLayout that itself includes a TextView and a Button. now how can I access to that TextView on view object?

Upvotes: 1

Views: 97

Answers (1)

Martin Cazares
Martin Cazares

Reputation: 13705

First of all the TextView you are trying to reach must have an id (e.g. @android:id="@+id/yourTxtId"), and then from your rootView, in your case the View you are actually inflating all you have to do is:

View view=inflater.inflate(com.example.R.layout.aaa, null);
TextView txt = (TextView)view.findViewById(R.id.yourTxtId);
//And here you have the reference...

Regards!

Upvotes: 1

Related Questions