dcsimg
Results 1 to 2 of 2

Thread: Content of Listview not show anythings when using the NavigationDrawer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2018
    Posts
    17

    Arrow Content of Listview not show anythings when using the NavigationDrawer

    I am new in android programming, my project is about getting RSS Feeds from web ,it works fine, then I have moved the app to be in Navigation drawer menu.
    Then the application become not working I'm sure there is no error on code but in onActivityCreated() method "I think that !". anyway this my code>>

    my Main Activity:
    Code:
        public class MainActivity extends AppCompatActivity
            implements NavigationView.OnNavigationItemSelectedListener {
        NavigationView navigationView=null;
        Toolbar toolbar=null;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            RssFragment fragment=new RssFragment();
            android.support.v4.app.FragmentTransaction fragmentTransaction=getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fragment_container,fragment);
            fragmentTransaction.commit();
            toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.addDrawerListener(toggle);
            toggle.syncState();
    
            navigationView = (NavigationView) findViewById(R.id.nav_view);
            navigationView.setNavigationItemSelectedListener(this);
        }
    my RssFragment:
    Code:
        public class RssFragment extends Fragment implements AdapterView.OnItemClickListener {
    
        private ProgressBar progressBar;
        private ListView listView;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_rss, container, false);
            progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
            listView = (ListView) view.findViewById(R.id.listView);
            listView.setOnItemClickListener(this);
            final SwipeRefreshLayout pullToRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
            pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    startService();
                    pullToRefresh.setRefreshing(false);
                }
            });
            return view;
        }
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            startService();
        }
    
        private void startService() {
            Intent intent = new Intent(getActivity(), RssService.class);
            getActivity().startService(intent);
        }
    
        /**
         * Once the {@link RssService} finishes its task, the result is sent to this BroadcastReceiver
         */
        private BroadcastReceiver resultReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                progressBar.setVisibility(View.GONE);
                List<RssItem> items = (List<RssItem>) intent.getSerializableExtra(RssService.ITEMS);
                if (items != null) {
                    RssAdapter adapter = new RssAdapter(getActivity(), items);
                    listView.setAdapter(adapter);
                } else {
                    Toast.makeText(getActivity(), "An error occurred while downloading the rss feed.",
                            Toast.LENGTH_LONG).show();
                }
            }
        };
    
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            RssAdapter adapter = (RssAdapter) parent.getAdapter();
            RssItem item = (RssItem) adapter.getItem(position);
            Uri uri = Uri.parse(item.getLink());
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
        @Override
        public void onStart() {
            super.onStart();
            IntentFilter intentFilter = new IntentFilter(RssService.ACTION_RSS_PARSED);
            LocalBroadcastManager.getInstance(getActivity()).registerReceiver(resultReceiver, intentFilter);
        }
    
        @Override
        public void onStop() {
            super.onStop();
            LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(resultReceiver);
        }
    my app_bar_main :
    Code:
        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:id="@+id/fragment_container"
            android:layout_height="match_parent" />
    this is was the main activity in the app that call RssFragment before moved to navigition drawer main activity :
    Code:
        public class MainActivity extends AppCompatActivity {
        @Override   
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            if (savedInstanceState == null) {
                addRssFragment();
            }
        }
        private void addRssFragment() {
    
            FragmentManager manager = getSupportFragmentManager();
            FragmentTransaction transaction = manager.beginTransaction();
            RssFragment fragment = new RssFragment();
            transaction.add(R.id.fragment_container, fragment);
            transaction.commit();
        }
        }
    I really want help with that!!

    Note: The application was working well but when I moved it to navigation drawer it did not work and the activity does not show anything,just swipe to refresh widget.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,380

    Re: Content of Listview not show anythings when using the NavigationDrawer

    You have posted in the Mobile CodeBank forum. All CodeBank forums are for sharing working code snippets with others, not for asking questions. I have asked the mods to move this thread to a more appropriate forum. Please don't create a duplicate thread in the mean time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width