我有一个支持片段活动,它将加载不同的片段。该片段具有一些textView
,其id =“score”
,我想获取它的句柄,但是对于得分的textView
的findViewById
返回null。为什么会这样?
textView位于片段中。
public class MyActivity extends extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks{
private TextView scoreBoardTextView = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
scoreBoardTextView = (TextView) findViewById(R.id.score); //this returns null
}
@Override
public void onNavigationDrawerItemSelected(int position) {
//set fragment
}
}
TextView
属于fragment
的布局还是MainActivity
的布局? - user2121