Я использую FragmentPagerAdapter в моем android проекте. Я тоже использую socket.io и мне нужно обновить sh просмотр списка во фрагменте после получения данных через сокет.
FragmentPagerAdapter
public class SectionsPagerAdapter extends FragmentPagerAdapter {
@StringRes
private static final int[] TAB_TITLES = new int[]{R.string.tab_text_1, R.string.tab_text_2};
private final Context mContext;
public SectionsPagerAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
Collections collections = new Collections();
return collections;
case 1:
List list = new List();
return list;
default:
return null;
}
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return mContext.getResources().getString(TAB_TITLES[position]);
}
@Override
public int getCount() {
// Show 2 total pages.
return TAB_TITLES.length;
}
}
Ниже приведен мой фрагмент код:
фрагмент списка
public class List extends Fragment {
JSONArray LIST_DATA = new JSONArray();
ListViewAdapter listAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list, container, false);
ListView listView = view.findViewById(R.id.listView);
FloatingActionButton addSong = view.findViewById(R.id.addButton);
GetterSetter getterSetter = new GetterSetter();
JSONObject jsonObject = getterSetter.getJsonObject();
try {
LIST_DATA = jsonObject.getJSONArray("list");
} catch (JSONException e) {
e.printStackTrace();
}
listAdapter = new ListViewAdapter(getActivity(), LIST_DATA);
listView.setAdapter(listAdapter);
addSong.setOnClickListener(new FloatingActionButton.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(getActivity(), AddSong.class);
startActivity(intent);
}
});
return view;
}
и мой socket.io
приемник SocketIo
private Ack createSong = new Ack() {
@Override
public void call(final Object... args) {
runOnUiThread(new Runnable() {
@Override
public void run() {
JSONArray GRID_DATA = new JSONArray();
try {
GRID_DATA = new JSONArray(""+args[1]);
} catch (JSONException e) {
e.printStackTrace();
}
GetterSetter getterSetter = new GetterSetter();
getterSetter.setJsonArray(GRID_DATA);
Log.d("name", String.valueOf(GRID_DATA));
finish();
}
});
}
};
Как я могу обновить sh мой адаптер списка после вызванного метода fini sh ()?