Button click event not fire properly in <include> tag in ANDROID -


i have 3 xml files

1) header 2) firstactivity 3) secondactivity.

header.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <button  android:text="button 1"  android:id="@+id/button1"  android:layout_width="wrap_content"  android:layout_height="wrap_content" android:onclick="first1" > </button>  <button  android:text="button 2"  android:id="@+id/button2"  android:layout_width="wrap_content"  android:layout_height="wrap_content" android:onclick="second" > </button> </linearlayout> 

firstactivity.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout      xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <include layout="@layout/headerfile"/>  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margintop="100dip" > <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="phone detail" android:textappearance="?android:attr/textappearancelarge" /> <textview android:id="@+id/simid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/imeino" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" />  <textview android:id="@+id/phoneno" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" />   </linearlayout> </relativelayout> 

headeractivity.java

public class headeractivity extends activity { button b1,b2; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.headerfile);   b1 = (button)findviewbyid(r.id.button1) ; b2 = (button)findviewbyid(r.id.button2) ;  } //oncreate on  public void first1(view v) { intent =new intent(this,firstactivity.class); startactivity(i); finish();        }  public void second(view v) { intent i1 =new intent(this, secondactivity.class); startactivity(i1);   finish(); } } 

but got error every time …

log-cat :

error/androidruntime(328): java.lang.illegalstateexception: not find method first1 (view) in activity class com.contactdetails.contactdetailsactivity onclick handler on view class  android.widget.button id 'button1' 

in contactdetailsactivity.java class should add below method

public void first1(view v) { // onlick code  } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -