Please can anyone help me, since i am new to android i am not able to get solution for - the button OnClick event is not working if i use the inflated layout. Here is my usemerge.xml code,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2996ff" >
<LinearLayout
android:id="@+id/i1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
</LinearLayout>
</RelativeLayout>
toplayout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/butt1"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginStart="20dp"
android:layout_marginTop="24dp"
android:background="@drawable/mybutton"
android:text="@string/schedule" />
</LinearLayout>
MainActivity.java
private LinearLayout lin1;
private Button bt1;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.usemerge);
final LayoutInflater inflater =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
lin1 = (LinearLayout)findViewById(R.id.i1);
View vi=inflater.inflate(R.layout.toplayout,lin1,false);
lin1.addView(vi);
bt1=(Button)vi.findViewById(R.id.butt1);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vo) {
// TODO Auto-generated method stub
Intent ain=new Intent(getBaseContext(), ScheduleActivity.class);
startActivity(ain);
}
});