KeniaKaleyk
New Member
I add the onclick method to my button in the \[code\]fragment2.xml\[/code\]\[code\] <Button android:id="@+id/getTextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Kliknij do fragment 1" androidnClick="onClick" />\[/code\]Then defined this method in Fragment2.java\[code\]public void onClick(View view){}\[/code\]But when I click on it the app crashes? What is wrong full XML and java file below\[code\]package com.example.fragments;import android.app.Fragment;import android.os.Bundle;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;public class Fragment2 extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance){ Log.d("Fragment 2", "metoda"); return inflater.inflate(R.layout.fragment2, container, false); } public void onClick(View view){}}\[/code\]\[code\]<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" androidrientation="vertical" android:background="#FFFF00" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Fragment 2" android:textColor="#0000FF" android:textSize="25sp"/> <!-- moze byc px dp sp --> <Button android:id="@+id/getTextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Kliknij do fragment 1" androidnClick="onClick" /></LinearLayout>\[/code\]