2014-10-07 7 views
0

안녕하세요 내가 처음이 시작할 때 작업 표시 줄의 활동 목록보기를 구현 오전하지만 내가 코드를 아래에 시도안드로이드에서 작업 표시 줄 활동이 시작될 때 조각이 작동하지 않습니까?

작동하지 않습니다하지만 난 그냥이

액션 바 배우기 시작했습니다 나를 위해 작동하지 않습니다

MainActivity.java

public class MainActivity extends ActionBarActivity implements 
     NavigationDrawerFragment.NavigationDrawerCallbacks { 

    /** 
    * Fragment managing the behaviors, interactions and presentation of the 
    * navigation drawer. 
    */ 
    private NavigationDrawerFragment mNavigationDrawerFragment; 

    /** 
    * Used to store the last screen title. For use in 
    * {@link #restoreActionBar()}. 
    */ 
    private CharSequence mTitle; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.navigation_drawer); 
     mTitle = getTitle(); 

     // Set up the drawer. 
     mNavigationDrawerFragment.setUp(R.id.navigation_drawer, 
       (DrawerLayout) findViewById(R.id.drawer_layout)); 

     Fragment fr=new FragmentOne(); 
     FragmentManager fragmentManager = getSupportFragmentManager(); 
     fragmentManager .beginTransaction().replace(R.id.container, fr); 

    } 

    @Override 
    public void onNavigationDrawerItemSelected(int position) { 
     // update the main content by replacing fragments 



    } 


    public void restoreActionBar() { 


     ActionBar actionBar = getSupportActionBar(); 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); 
     actionBar.setDisplayShowTitleEnabled(true); 
     actionBar.setTitle(mTitle); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     if (!mNavigationDrawerFragment.isDrawerOpen()) { 
      // Only show items in the action bar relevant to this screen 
      // if the drawer is not showing. Otherwise, let the drawer 
      // decide what to show in the action bar. 
      getMenuInflater().inflate(R.menu.main, menu); 
      restoreActionBar(); 
      return true; 
     } 
     return super.onCreateOptionsMenu(menu); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

    public static class FragmentOne extends Fragment { 


      private String[] mStrings={ 
        "http://androidexample.com/media/webservice/LazyListView_images/image0.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image1.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image2.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image3.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image4.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image5.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image6.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image7.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image8.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image9.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image10.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image0.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image1.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image2.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image3.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image4.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image5.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image6.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image7.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image8.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image9.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image10.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image0.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image1.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image2.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image3.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image4.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image5.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image6.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image7.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image8.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image9.png", 
        "http://androidexample.com/media/webservice/LazyListView_images/image10.png" 

      }; 

      @Override 
      public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) { 


       return inflater.inflate(R.layout.fragmentone,container,false); 

      } 


      @Override 
      public void onActivityCreated(Bundle savedInstanceState) { 

       super.onActivityCreated(savedInstanceState); 

       ListView listview=(ListView) getActivity().findViewById(R.id.listView); 

        // Create custom adapter for listview 
       LazyImageLoadAdapter adapter=new LazyImageLoadAdapter(getActivity(), mStrings); 

       //Set adapter to listview 
       listview.setAdapter(adapter); 


      } 

     } 
} 
+1

자세한 정보 공유 : 예를 들어 로그, 예외 사항 등. 처음에는 onCreate 메소드에서 부분 트랜잭션을 커밋해야합니다. 이 문제를 해결하면 이는 하나의 이유 일 수 있습니다.) –

+0

포인트를 얻지 못한다는 의미입니까? – Mahesh

+1

죄송합니다, 의미 : fragmentManager .beginTransaction(). replace (R.id.container, fr). ** 오류를 더 쉽게 만들기 위해 오류에 대한 더 많은 정보를 첨부하는 것을 잊지 마십시오. –

답변

1

트랜잭션을 커밋!

fragmentManager.beginTransaction().replace(R.id.container, fr).commit(); 
관련 문제