I have a situation for my Android application. Scenario: I use a viewpage adapter, I have 3 pages, which are actually fragments. My problems are that I want to update them from the dialog activity. the list from whose onclick event I want to update the fragment.
First of all, it is possible, if so, please make a chip and help me.
Greetings Gaurav
This is my view page adapter.
package com.punksrant.ifinddryday.adapter; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import com.punksrant.ifinddryday.fragment.AllFragment; import com.punksrant.ifinddryday.fragment.HomeFragment; import com.punksrant.ifinddryday.fragment.SynchFragment; import com.punksrant.ifinddryday.utils.IFindDryDaysConstants; import com.viewpagerindicator.TitleProvider; public class ViewPagerAdapter extends FragmentPagerAdapter implements TitleProvider { private static String[] titles = IFindDryDaysConstants.titles; public ViewPagerAdapter(FragmentManager fm) { super(fm); } @Override public String getTitle(int position) { return titles[position % titles.length].toUpperCase(); } @Override public int getCount() { return titles.length; } @Override public Fragment getItem(int position) { Fragment fragment; switch (position) { case 0: fragment = HomeFragment.newInstance(); break; case 1: fragment = AllFragment.newInstance(); break; case 2: fragment = SynchFragment.newInstance(titles[position % titles.length]); break; default: fragment = HomeFragment.newInstance(); } return fragment; } } ' and in this I want to refresh the home fragment from my dialog class ' package com.punksrant.ifinddryday.activity; import roboguice.inject.ContentView; import roboguice.inject.InjectView; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockFragmentActivity; import com.google.inject.Inject; import com.punksrant.ifinddryday.model.Coordinates; import com.punksrant.ifinddryday.utils.DryDayJSONResParser; import com.punksrant.ifinddryday.utils.IFindDryDayViewUtils; @ContentView(R.layout.statedialog) public class Dialog extends RoboSherlockFragmentActivity { @InjectView(R.id.dialogList) ListView listView; @Inject SharedPreferences preferences; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] states = DryDayJSONResParser.getSupportedStates(); listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, states)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String state = ((TextView) view).getText().toString(); Coordinates coordinates = IFindDryDayViewUtils .getCoordinatesFromPreferences(preferences); coordinates.setState(state); IFindDryDayViewUtils.updateCityFromLocation(coordinates, preferences); finish(); } }); } },
source share