我的Activity
包含custom ActionBar and ViewPager
,其中包含三个标签。
EditText
上的click
按钮时,我无法从ActionBar
内的public class TranAdd extends FragmentActivity...{
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
EditText et;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
et = (EditText) mViewPager.findViewById(R.id.editText);
//...reference null...
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
TextView textViewTitle = (TextView) mCustomView.findViewById(R.id.textViewTitle);
textViewTitle.setText("New Transaction");
ImageView imageViewOk = (ImageView) mCustomView.findViewById(R.id.imageViewOk);
imageViewOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String txt = et.getText().toString();
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}
内阅读文字。
EDITED: 包含TABS ......
public class Fragment extends Fragment...{
...
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
}
FRAGMENT:
{{1}}
答案 0 :(得分:0)
尝试在setHasOptionsMenu(true)
(标签)的onCreate()
方法中调用Fragment
,该方法需要与ActionBar
进行互动。