2014-09-21 50 views
1

我想要在活動中的片段中的我的按鈕「configbutton」的id,以便我可以調用活動中聲明的某些方法。但我無法這樣做。 有沒有辦法做到這一點。 Activity類嘗試引用活動中的片段按鈕

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); 
} 

片段類

​​3210

如果有什麼辦法你知道PLZ共享代碼。 我想要引用活動類中片段中的按鈕,以便可以從活動類調用該按鈕的偵聽器。這是可能的。 thanku

+0

可能重複http://stackoverflow.com/questions/12659747/call-an-activity-method-from-a-fragment – 2014-09-21 13:21:07

回答

0

你不能在片段中定義這個按鈕,然後調用這樣的活動方法嗎?

((YourActivityClassName)getActivity()).yourPublicMethod();