返回改造响应值

时间:2019-11-08 15:03:17

标签: android retrofit

我要返回改造响应吗?

我尝试过,但是找不到任何答案?我也尝试使用SharedPreferences,但是对于第一步非常有用。当我给全班打电话时,它第一次起作用了吗?这是我的代码。

public class NoteClass {

    String MetaKey;
    public String MetaValue;

    SharedPreferences shared_guidace;
    public static final String mypref_guidace  = "mypref_guidace";
    public static String GuidanceText = "GuidanceTextKey";

    public void getGuidanceText (String metaKey , final Context Getcontext)
    {
        GetConfigObject getConfigObject = new GetConfigObject();

        getConfigObject.setMetaKey(metaKey);

        GetConfigRequest getConfigRequest = RetrofitHelper.getInstance().getRetrofit().create(GetConfigRequest.class);
        getConfigRequest.getConfigFunc(getConfigObject).enqueue(new Callback<GetConfigModel>() {
            @Override
            public void onResponse(Call<GetConfigModel> call, Response<GetConfigModel> response) {
                if(response.isSuccessful())
                {
                    shared_guidace = Getcontext.getSharedPreferences(mypref_guidace, Context.MODE_PRIVATE);

                    if(response.body().getGetConfigResult().getStatus())
                    {
                        MetaValue = response.body().getGetConfigResult().getData().getMetaValue();

                        shared_guidace = Getcontext.getSharedPreferences(mypref_guidace, Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = shared_guidace.edit();
                        editor.putString(GuidanceText , MetaValue);
                        editor.commit();
                    }
                    else
                    {
                        Toast.makeText( Getcontext , response.body().getGetConfigResult().getMessage() , Toast.LENGTH_LONG).show();
                    }
                }
            }

            @Override
            public void onFailure(Call<GetConfigModel> call, Throwable t) {
                Toast.makeText(  Getcontext ,"err." , Toast.LENGTH_LONG ).show();
            }
        });
    }

    public String Guidance(final Context Getcontext)
    {
        shared_guidace = Getcontext.getSharedPreferences(mypref_guidace, Context.MODE_PRIVATE);
        String Value = shared_guidace.getString( GuidanceText , "");

        return Value;
    }}

        // i call it 

        GuidanceNoteClass guidanceNoteClass2 = new GuidanceNoteClass();
        guidanceNoteClass2.getGuidanceText("view" ,  getContext() );
        String view = guidanceNoteClass2.Guidance( getContext() );

        GuidanceNoteClass guidanceNoteClass3 = new GuidanceNoteClass();
        guidanceNoteClass3.getGuidanceText("edit" ,  getContext() );
        String edit = guidanceNoteClass3.Guidance( getContext() );

我叫过两次课,但结果是第二课与第一课相同。

0 个答案:

没有答案