[英]trying refer to button of fragment from activity
我想要活動片段中的按鈕“ configbutton”的ID,以便我可以調用活動中聲明的某些方法。 但是我做不到。 有什么辦法可以做到這一點。 活動課
public class UartLoopBackActivity extends FragmentActivity implements
ActionBar.TabListener {
Button configButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_analysis);
configButton = (Button) findViewById(R.id.configButton);
}
片段類
public class DataShown extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("3", "started");
View rootView = inflater.inflate(R.layout.datashown, container, false);
Log.d("3", "closed");
Button tv = (Button) rootView.findViewById(R.id.configButton);
return rootView;
}
}
如果有任何方法,您知道請共享代碼。 我想引用活動類中片段中的按鈕,以便可以從活動類中調用該按鈕的偵聽器。 有可能嗎 感謝你
不能在片段中定義此按鈕,然后像這樣調用活動方法嗎?
((YourActivityClassName)getActivity()).yourPublicMethod();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.