Rss Parser using fragment« Back to Previous Page

I am trying to fetch RSS feeds and display in different fragment tabs. Main Activity
package bt.yj.btnews;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.os.Bundle;


public class MainActivity extends Activity {

    //declare Tab variable
    ActionBar.Tab tab;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // create actionbar
        ActionBar actionBar = getActionBar();
        //Hide actionbar
        actionBar.setDisplayShowHomeEnabled(true);
        //hide actionbar title
        actionBar.setDisplayShowTitleEnabled(true);
        // create actionbar tabs
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        // Create first Tab
        tab = actionBar.newTab().setTabListener(new Kuensel());
        // Create your own custom icon
        //tab.setIcon(R.drawable.tab1);
        tab.setText(R.string.KO);
        actionBar.addTab(tab);
        // Create Second Tab
        tab = actionBar.newTab().setTabListener(new BBS());
        // Set Tab Title
        tab.setText(R.string.BBS);
        actionBar.addTab(tab);
        // Create Second Tab
        tab = actionBar.newTab().setTabListener(new BO());
        // Set Tab Title
        tab.setText(R.string.BO);
        actionBar.addTab(tab);
        // Create Second Tab
        tab = actionBar.newTab().setTabListener(new tb());
        // Set Tab Title
        tab.setText(R.string.TB);
        actionBar.addTab(tab);
    }

}
Fragemnt/Tab Activity
package bt.yj.btnews;

import android.app.ActionBar;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class BBS extends Fragment implements ActionBar.TabListener {
    private Fragment bbsFragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view
        getActivity().setContentView(R.layout.layout_bbs);


    }

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

        try {
            RSSReader rssReader = new RSSReader("http://www.bbs.bt/news/?feed=rss2");
            ListView Items = (ListView)MView.findViewById(R.id.listViewBBS);
            /*ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, rssReader.getItems());*/
            ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, rssReader.getItems());
            Items.setAdapter(adapter);
            Items.setOnItemClickListener(new ListListener(rssReader.getItems(), getActivity()));
        } catch (Exception e) {
            Log.e("BTNews", e.getMessage());
        }

        return MView;
    }

    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        bbsFragment = new BBS();
        ft.add(android.R.id.content, bbsFragment);
        ft.attach(bbsFragment);
    }

    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        // Remove fragment1.xml layout
        ft.remove(bbsFragment);
    }

    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }
}
Posted by ictbhutan (Questions:1, Answers:1)
Asked on September 12, 2013 7:15 am
Category: Android
1

What you are missing here my friend is loading RSS data in the separate thread. You should use AsyncTask for that. Take a look at this example – http://www.itcuties.com/android/android-asynctask-rss-reader/. You will find there the ITCutiesReaderAppActivity. Implement your code the same way as ITCuties did. Cheers!

Posted by charlie (Questions:9, Answers:15)
Answered On September 14, 2013 12:39 pm #
1

This is the error that i get when i run app. Couldn’t open http://www.bbs.bt/news/?feed=rss2 or JAVA i/o

Posted by ictbhutan (Questions:1, Answers:1)
Answered On September 13, 2013 5:07 am #
No account?



It's FREE!

Like what you have found?


... and keep us going