Merge ListViews Android

0

In my application, I have two Fragments, one to load Tweets and one to Read an RSS. RSS

public class RssFragment extends ListFragment {

    private RssListAdapter adapter;

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

            List<JSONObject> jobs = new ArrayList<JSONObject>();
            try {
                jobs = RssReader.getLatestRssFeed();
            } catch (Exception e) {
                Log.e("RSS ERROR", "Error loading RSS Feed Stream >> " + e.getMessage() + " //" + e.toString());
            }

            adapter = new RssListAdapter(getActivity(),jobs);
            setListAdapter(adapter);

            return super.onCreateView(inflater, container, savedInstanceState);    

    }

Tweets
public class Noticias extends ListFragment {
    final static String twitterScreenName = "";
    final static String TWITTER_API_KEY = "";
    final static String TWITTER_API_SECRET = "";
    private static final String TAG = "Tweet";


    @Override  
      public void onListItemClick(ListView l, View v, int position, long id) {  
       //new CustomToast(getActivity(), numbers_digits[(int) id]);     
      }  

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

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
        .permitNetwork()
        .build());

            ArrayList<TwitterTweet> twitterTweets = null;
            TwitterAPI twitterAPI = new TwitterAPI(TWITTER_API_KEY,TWITTER_API_SECRET);
            twitterTweets = twitterAPI.getTwitterTweets("LinkOffTMMG");

            ArrayAdapter<TwitterTweet> adapter = new ArrayAdapter<TwitterTweet>(  
                inflater.getContext(), R.layout.twitter_tweets_list,  
                R.id.listTextView, twitterTweets);  

            setListAdapter(adapter);  

            return super.onCreateView(inflater, container, savedInstanceState);    

    }
}

How do I create another Fragment while the content of the other two sorted by the most recent date?

    
asked by anonymous 20.01.2015 / 12:56

1 answer

1

You need to program based on Interfaces.

In short, create an interface that contains two methods, one to get the news photo and the other to get the news headline. After that, create a custom adapter that inherits from BaseAdapter and receives a list of that interface. Ready! : -)

public interface Noticia {
   Bitmap getFoto();
   String getTitulo();
}

public class NoticiaAdapter extends BaseAdapter {

   private List<Noticia> mNoticias;

   public NoticiaAdapter(Context context, List<Noticia> noticias) {
      this.mNoticias = noticias;
   }

   getCount(...) { ... }
   getItem(...) { ... }
   getItemId(...) { ... }
   getView(...) { ... }

}
    
22.01.2015 / 19:45