How can I get reference to <include> elements(Can I get reference by id to an element in layout that I add through <include> tag)?
Get reference by using findViewById
See the following Example
RelativeLayoutTesting.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
public class RelativeLayoutTesting extends Activity {
android.widget.RelativeLayout currentView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
// set the relative layout as our view
setContentView(R.layout.main1);
EditText et = (EditText) findViewById(R.id.myEditText);
et.setText("My Edit");
}
}
main1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff">
<ImageButton
android:id="@+id/alpha"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#ff0000" />
<include
layout="@layout/edittext_layoout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
edittext_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With