嗨,im试图从Action访问文本视图,例如,当按下按钮时,我希望操作栏中的文本视图发生变化。这有可能吗?
下面是带有actionbar的代码MainActivity
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
preferences = PreferenceManager.getDefaultSharedPreferences(this);
new URLAsyncCaller().execute();
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
FragmentManager fragmentManager = getSupportFragmentManager();
ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.actionbar_layout);
LinearLayout search = (LinearLayout) actionBar.getCustomView().findViewById (R.id.btn_chart);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("lastid", 1); // also puts the data into a shared
editor.commit();
TextView toptitle= (TextView)search.findViewById(R.id.tv_avtiontext);
toptitle.setText(GWave.getActiontext());`帧B码
GWave.setActiontext("Welcome To Z-Wave");我尝试过在主活动中创建一个方法来处理文本更改,但是无法让它正常工作。如有任何建议,我们将不胜感激。谢谢。
发布于 2014-08-03 15:40:21
假设您的TextView中的ActionBar有一个id action_text,
在Fragment中,执行以下操作:
TextView actionText = (TextView) getActivity().findViewById(R.id.action_text); 等等!你完了!:)
https://stackoverflow.com/questions/25106199
复制相似问题