Java – invoke the method from another fragment.
                                        
                    •
                    Android                                    
                I've been trying for a while (searching here at the same time) to help me refresh listview in my mainframe. When I press a button in other clips. Sommene can explain how I make it work?
This is a mainframe with this feature (I exclude other features because I can't see how they contribute):
public class MainFragment extends Fragment {
public void otherList() {
    sqlite db = new sqlite(getActivity());
    db.open();
    Calendar sCalendar = Calendar.getInstance();
    String day = sCalendar.getDisplayName(Calendar.DAY_OF_WEEK,
            Calendar.LONG, Locale.ENGLISH);
    Cursor c = db.getAllRecords(day);
    Calendar cal = Calendar.getInstance();
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    arrayOfBars.clear();
    if (c.moveToFirst()) {
        do {
            String country = c.getString(0);
            String city = c.getString(1);
            String bar = c.getString(2);
            String timeStart = c.getString(3);
            String[] h = timeStart.split(":");
            int times = Integer.parseInt(h[0]);
            String timeEnd = c.getString(4);
            String[] h2 = timeEnd.split(":");
            int timee = Integer.parseInt(h2[0]);
            String placeLaLo = c.getString(5);
            String description = c.getString(6);
            String likes = c.getString(7);
            String offer = c.getString(8);
            if (hour < (times + 1) || hour < (timee)) {
                getPrefs = PreferenceManager
                        .getDefaultSharedPreferences(MainFragment.this
                                .getActivity());
                boolean lay = getPrefs.getBoolean("boolean", false);
                if (lay == true) {
                    while (times < timee) {
                        timeStart = times + ":" + h[1];
                        times++;
                        timeEnd = times + ":" + h2[1];
                        arrayOfBars.add(new BarObject(country, city, bar,
                                timeStart, timeEnd, placeLaLo, description,
                                likes, offer, bar));
                    }
                } else {
                    arrayOfBars.add(new BarObject(country, city, bar,
                            timeStart, timeEnd, placeLaLo, description,
                            likes, offer, bar));
                }
            }
        } while (c.moveToNext());
        Collections.sort(arrayOfBars, new BarObject.CompST());
        lv2.setAdapter(null);
        adapter = new BarAdapter(getActivity(), arrayOfBars);
        lv2.setAdapter(adapter);
    } else {
        Toast.makeText(getActivity(), "No database found",
                Toast.LENGTH_LONG).show();
    }
    db.close();
}
}
This is another clip:
public class SocialMedia extends Fragment {
ImageButton facebook, twitter, layoutS;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.social_media, container, false);
    layoutS = (ImageButton) view.findViewById(R.id.ibLayout);
    layoutS.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences getPrefs = PreferenceManager
                    .getDefaultSharedPreferences(SocialMedia.this
                            .getActivity());
            boolean lay = getPrefs.getBoolean("boolean", false);
            SharedPreferences.Editor e = getPrefs.edit();
            lay = !lay;
            e.putBoolean("boolean", lay);
            e.commit();
                            //Here I want to call otherList() from MainFragment
        }
    });
    return view;
}
}
resolvent:
FragmentManager fm = getFragmentManager(); 
MainFragment fragm = (MainFragment)fm.findFragmentById(R.id.main_fragment); 
fragm.otherList(); 
This code works best for me. And it looks easy
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        