【发布时间】:2014-02-08 18:01:10
【问题描述】:
我正在尝试将我的应用程序转换为片段与活动,以便更好地遵循带有导航抽屉的 android 设计指南。
我有一个带有按钮的片段,按下该按钮时会执行此代码以启动一个新片段:
FragmentManager man=getFragmentManager();
FragmentTransaction tran=man.beginTransaction();
Fragment_one=new Fragment1();
tran.add(R.id.main, Fragment_one);//tran.
tran.addToBackStack(null);
tran.commit();
它尝试加载的片段是这样的:
public class BPTopBeers extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
String userName = prefs.getString("userName", null);
String userID = prefs.getString("userID", null);
String title = "Top Beers on Beer Portfolio";
TextView topTitle = (TextView) findViewById(R.id.topTasteTitle);
topTitle.setText(title);
//construct url
String url = "myURL";
Log.d("myUrl", url);
//async task goes here
new GetYourTopTasteBeers(this).execute(url);
// Inflate the layout for this fragment
//todo: change to discover layout
return inflater.inflate(R.layout.toptaste_layout, container, false);
}
}
我在上述代码的这一行遇到错误:
TextView topTitle = (TextView) findViewById(R.id.topTasteTitle);
cannot resolve method findviewbyid 是错误
【问题讨论】:
标签: android android-fragments android-xml