我在主要活动的片段和文本框中有一个Button。现在,如果我将按片段中的按钮,将在文本框中打印一些消息。怎么做?
public class MessageFragment extends Fragment实现了View.OnClickListener {
public buttonPress press;
public interface buttonPress {
void getText (String inputText);
}
private Button button;
public MessageFragment(){}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_message, container);
button = (Button) view.findViewById(R.id.btn);
button.setOnClickListener(this);
return view;
}
@Override
public void onClick(View view) {
press.getText("Received from fragmnet");
}
}