your problem is in xml file you set attributes OnClick="sendText" and defining method in fragment Actually you have to defining it in MainActivity not it Fragment
public void sendText(View view){
// your code ....
}
Actually you this way do not Applied encapsulation object oriented properties – so best way to do it like this : you have to override onCreateView method in NotesFragment class to set onClickListner like this
private Button foo; // as globle var
private OnButtonsClicked boo; // as globle var
public void onAttach(Activity activity) {
super.onAttach(activity);
this.boo = (OnButtonsClicked) activity;
}
public interface OnButtonsClicked {
public void sendText(View v);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.notes,
container, false);
foo = view.findViewByid(R.id.foo); // button id
foo.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
boo.sendText(v);
}
});
return view;
}
and in your Activity implement OnButtonsClicked interface like this
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener, NotesFragment.OnButtonsClicked {
// your code ....
@override
public void sendText(View v){
// button click code here
}
}