如何在android中使用排序后的新数据刷新适配器?

如何在android中使用排序后的新数据刷新适配器?,android,android-fragments,refresh,fragmentpageradapter,Android,Android Fragments,Refresh,Fragmentpageradapter,我在应用程序中使用FragmentPagerAdapter。总共有3个选项卡,在对数据进行排序后,我无法获取新数据 有人能帮我解决这个问题吗 这是我的代码: public class PagerAdapter extends FragmentPagerAdapter { @SuppressWarnings("WeakerAccess") public final int tabCount; // private String categorySearchPath;

我在应用程序中使用FragmentPagerAdapter。总共有3个选项卡,在对数据进行排序后,我无法获取新数据

有人能帮我解决这个问题吗

这是我的代码:

public class PagerAdapter extends FragmentPagerAdapter {

    @SuppressWarnings("WeakerAccess")
    public final int tabCount;
//    private String categorySearchPath;
    private List<String> categorySearchPath;
    private String categoryTitle;
    public static String TAG="Pager";
    MyAlert myAlert=new MyAlert();
    public static SortingRequest sortRequest = new SortingRequest();



    public PagerAdapter(FragmentManager fm, int tabCount,List<String> categorySearchPath,String categoryTitle) {
        super(fm);
        this.tabCount = tabCount;
        this.categorySearchPath=categorySearchPath;
        this.categoryTitle=categoryTitle;
    }



    @Override
    public Fragment getItem(int position) {

        String searchedText="";
        int someParameter=-1;

        switch (position) {
            case 0:
                @SuppressWarnings("UnnecessaryLocalVariable")
                FragmentOnlineRetailers fr = new FragmentOnlineRetailers();
                fr.callSearchFragOnline(searchedText);

                //category
                Bundle bundle = new Bundle();
                bundle.putStringArrayList("ListOfCategorySearchPath", (ArrayList<String>) categorySearchPath);
                bundle.putString("categoryTitle",categoryTitle);
                fr.setArguments(bundle);
                fr.categorySearchFlow(searchedText);

                return fr;

            default:
                return null;

        }



    }

    @Override
    public int getCount() {
        return tabCount;
    }


}
公共类PagerAdapter扩展了FragmentPagerAdapter{
@抑制警告(“弱化访问”)
公共最终整数tabCount;
//私有字符串类别搜索路径;
私有列表类别搜索路径;
私有字符串分类;
公共静态字符串TAG=“Pager”;
MyAlert MyAlert=新建MyAlert();
public static SortingRequest sortRequest=new SortingRequest();
公共页面编辑器(FragmentManager fm、int tabCount、List categorySearchPath、String CategoryStitle){
超级(fm);
this.tabCount=tabCount;
this.categorySearchPath=categorySearchPath;
this.categorytle=categorytle;
}
@凌驾
公共片段getItem(int位置){
字符串searchedText=“”;
int someParameter=-1;
开关(位置){
案例0:
@抑制警告(“不必要的局部变量”)
FragmentOnlineRetailers fr=新的FragmentOnlineRetailers();
fr.callSearchFragOnline(searchedText);
//类别
Bundle=新Bundle();
bundle.putStringArrayList(“ListOfCategorySearchPath”,(ArrayList)categorySearchPath);
bundle.putString(“categorytle”,categorytle);
fr.setArguments(bundle);
fr.categorySearchFlow(searchedText);
返回fr;
违约:
返回null;
}
}
@凌驾
public int getCount(){
返回tabCount;
}
}
公共类MyAlert扩展了DialogFragment{

public static final String TAG="MyAlert";
public static String  searchedText="*";
private static Context context;
private Context mContext;
public static List<PPHits> listHitsSort=null;
private RecyclerView onlineRecycler;
final SortingRequest sortRequest = new SortingRequest();
private List<String> sort=new ArrayList<>();
private static int someParameter=-1;


public MyAlert() {

}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(getActivity());
    alertDialogBuilder.setTitle("Sort by");
    LayoutInflater li = getActivity().getLayoutInflater();
    @SuppressLint("InflateParams")
     final View promptsView = li.inflate(R.layout.popup_sortby, null);
    alertDialogBuilder.setView(promptsView);
    alertDialogBuilder.setCancelable(false);



    alertDialogBuilder.setSingleChoiceItems(R.array.sortList, -1, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            Log.d(TAG, "onClick: Sort Dialogue "+which);
            doSomeStuff(which);

        }
    });




    alertDialogBuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
           // vLayoutSort.setClickable(true);

            dismiss();
        }
    });





    alertDialogBuilder.setPositiveButton("SORT", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id ) {
           // vLayoutSort.setClickable(true);

            FragmentOnlineRetailers fragmentOnlineRetailers=new FragmentOnlineRetailers();<---second time object is created to access CALLSORT(), how to use same object without creating new object
            fragmentOnlineRetailers.callSort(searchedText);



        }

    });



    Dialog dialog=alertDialogBuilder.create();
    return dialog;
}




    //Sorting Call this method is in  FragmentOnlineRetailers  class

    public List<PPHits> callSort(final String searchText) {



        String searchSortText="*";

        APIService api_service;

        Log.d(TAG, "callFb: " + searchSortText);

        retrofit.Retrofit retrofit = new retrofit.Retrofit
                .Builder()
                .baseUrl("http:// --------.com:8080")
                .addConverterFactory(GsonConverterFactory.create())
                .build();


        api_service = retrofit.create(APIService.class);
        Log.d(TAG, "callSorting: Inside");

        Log.d(TAG, "callSorting: " + searchSortText);
        if (searchText != null) {

            Log.d(TAG, "callSorting: "+sortRequest);

            Call<ProductPageResponse> exampleCall = api_service.getSorted(sortRequest);
            exampleCall.enqueue(new Callback<ProductPageResponse>() {
                @Override
                public void onResponse(Response<ProductPageResponse> response, Retrofit retrofit) {

                    Log.d(TAG, "onResponse: Inside response");

                    if (response.code() == 200) {

                        Log.d(TAG, "onResponse: " + response.code());
                        Log.d(TAG, "onResponse: " + response.body());

                        ProductPageResponse ppr = response.body();
                        listHitsSort = ppr.getPpObj().getResult().getHits();


                        Log.d("Hello Moto", "callSorting: "+listHitsSort);



                        if(listHitsSort!=null) {

                            Log.d(TAG, "onResponse: Hello Sirji kya haal h");
                            Context activity = getActivity();



                            adapter = new OnlineRetailAdapter(listHitsSort,activity, R.layout.item_product);
                            onlineRecycler.setAdapter(adapter);




                        }else{
                            Log.d(TAG, "onResponse: Sorted list is NUll ");
                        }

                    }else
                    {
                        Log.d(TAG, "onResponse: product page not available");
                    }


                    Log.d(TAG, "onResponse: getting responser from server");

                }

                @Override
                public void onFailure(Throwable t) {

                    Log.d("callSorting", "onFailure:" + t.getMessage());


                }


            });

        }

        return listHitsSort;


    }
public static final String TAG=“MyAlert”;
公共静态字符串searchedText=“*”;
私有静态语境;
私有上下文;
公共静态列表ListHitsort=null;
私人回收站查看在线自行车;
最终排序请求sortRequest=新排序请求();
私有列表排序=新的ArrayList();
私有静态int-someParameter=-1;
公共MyAlert(){
}
@凌驾
创建对话框上的公共对话框(Bundle savedInstanceState){
final AlertDialog.Builder alertDialogBuilder=新建AlertDialog.Builder(getActivity());
alertDialogBuilder.setTitle(“排序依据”);
LayoutInflater li=getActivity().getLayoutInflater();
@SuppressLint(“充气参数”)
最终视图提示视图=li.充气(R.layout.popup_sortby,null);
alertDialogBuilder.setView(promptsView);
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setSingleChoiceItems(R.array.sortList,-1,新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
Log.d(标记“onClick:Sort Dialogue”+which);
doSomeStuff(哪个);
}
});
alertDialogBuilder.setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
public void onClick(DialogInterface对话框,int-id){
//vLayoutSort.setClickable(真);
解雇();
}
});
alertDialogBuilder.setPositiveButton(“排序”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
//vLayoutSort.setClickable(真);

FragmentOnlineTailers FragmentOnlineTailers=new FragmentOnlineTailers();一般来说,对片段调用公共方法是不正确的。此时未定义片段中的视图。还不清楚您有哪些代码。显示一个@Rucha Bhatt..thanx用于编辑您能建议一些与获得所需输出相关的内容吗。。