从ViewPager的EditTet中自定义ActionBar和gettext

时间:2015-03-12 15:25:42

标签: android android-actionbar android-viewpager

我的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}}

1 个答案:

答案 0 :(得分:0)

尝试在setHasOptionsMenu(true)(标签)的onCreate()方法中调用Fragment,该方法需要与ActionBar进行互动。