简体   繁体   English

Android SherlockFragmentActivity调用SherlockFragment

[英]Android SherlockFragmentActivity call SherlockFragment

Originally, I have 2 Activities. 最初,我有2个活动。 A call B activities. 一个电话B活动。 Now I changed the A class extends SherlockFragmentActivity and B class extends SherlockFragment. 现在我改变了A类扩展SherlockFragmentActivity和B类扩展了SherlockFragment。

I tried to changed these in A class: 我尝试在A类中更改这些:

   private class MyTabListener implements ActionBar.TabListener {
      @Override
      public void onTabSelected(Tab tab, FragmentTransaction ft) {

          if (tab.getPosition()==1) {
              B frag = new B();
              ft.replace(android.R.id.content, frag);

          }

      }

      @Override
      public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
      }

      @Override
      public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
      }


    }

//============================= // =============================

In B class: 在B班:

public class Br extends SherlockFragment{


    /* Called when the activity is first created */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.promotionslist_tableview);



        //get our listview
        ListView myListView = (ListView) findViewById(R.id.myListView_promotionslist_table);

//============================== // ==============================

BUT ERROR. 但错误。 1. onCreate 2. findViewById.. 1. onCreate 2. findViewById ..

What i am wrong ? 我错了什么?

please give me some hints. 请给我一些提示。 Thanks. 谢谢。

I can now display the B fragement but the listview overlap on the main listview..? 我现在可以显示B fragement,但listview重叠在主列表视图上..? Why ? 为什么?

public class B extends SherlockFragment{

    View view; 

    /* Called when the activity is first created */
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //setContentView(R.layout.promotionslist_tableview);





        //get our listview
        ListView myListView = (ListView) view.findViewById(R.id.myListView_promotionslist_table);
.
.
.
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.promotionslist_tableview, container, false);
        return view;
    }

You have to use the onCreateView() method in fragments: 您必须在片段中使用onCreateView()方法:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout, null);

        return view;
    }

There you can inflate a View and call findViewById like this: 在那里你可以膨胀视图并调用findViewById,如下所示:

view.findViewById(...);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android的SherlockFragmentActivity的SherlockFragment中未调用onResume()吗? - onResume() is not called in SherlockFragment of SherlockFragmentActivity in Android? 从SherlockFragmentActivity内的SherlockFragment启动Fragment-Android - Start Fragment from SherlockFragment inside a SherlockFragmentActivity - Android 如何将标签添加到SherlockFragment,而不是SherlockFragmentActivity中 - how to add tabs to a SherlockFragment, not in a SherlockFragmentActivity SherlockFragmentActivity(Android)中的ListView - ListView within SherlockFragmentActivity (Android) 具有多个ListFragments的Android SherlockFragmentActivity - Android SherlockFragmentActivity with multiple ListFragments Android SherlockFragmentActivity-选项卡 - Android SherlockFragmentActivity - Tab Android ImageView未在SherlockFragment中显示 - Android ImageView not showing in SherlockFragment Android:在SherlockActivity中调用了onOptionsItemSelected(),但在SherlockFragmentActivity中未调用 - Android: onOptionsItemSelected() called in SherlockActivity, but not in SherlockFragmentActivity Android:按钮OnClick在SherlockFragment中不起作用 - Android: Button OnClick not working in SherlockFragment Android如何在SherlockFragment中转换sherlockActivity - Android How to convert sherlockActivity in SherlockFragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM