小编y07*_*7k2的帖子

Retrofit 2.0抛出"IllegalArgumentException:@Field参数只能与表单编码一起使用".如何做正确的API查询并修复它?

我的问题是我不知道如何开始使用收到的API的Retrofit 2.0 - 下面提到...

首先,我需要用户名,密码,fbID(可选),gmailID(可选),twitID(可选),性别,birthDate,位置(不需要 - 如果long和lat有值),经度(可选),纬度(可选) ,profileImage(可选).

当所有参数都很好时 - 接收status = true.如果不是 - 接收status = false和所需的参数错误(例如已经收到邮件)

所以我可以接收 status = true 或者 status = false使用最多5个参数(用户名,电子邮件,密码,性别,birthDate)进行数组.

我试过这个API Interface:

public interface AuthRegisterUserApi {
    @PUT()
    Call<AuthRegisterUserModel> getStatus(
            @Field("username") String username,
            @Field("email") String email,
            @Field("password") String password,
            @Field("fbID") String fbID,
            @Field("gmailID") String gmailID,
            @Field("twitID") String twitID,
            @Field("gender") String gender,
            @Field("birthDate") String birthDate,
            @Field("location") String location,
            @Field("longitude") String longitude,
            @Field("latitude") String latitude,
            @Field("profileImage") String profileImage
            );

    class …
Run Code Online (Sandbox Code Playgroud)

java api android retrofit retrofit2

34
推荐指数
4
解决办法
4万
查看次数

如何处理Retrofit 2.0中的错误

我想在Retrofit 2.0中处理错误

得到eg code=404body=null,但errorBody()包含ErrorModel(Boolean statusString info)中的数据.

这是errorBody().content:[text=\n{"status":false,"info":"Provided email doesn't exist."}].

我怎样才能获得这些数据?

谢谢你的帮助!

这是我的Retrofit请求代码:

ResetPasswordApi.Factory.getInstance().resetPassword(loginEditText.getText().toString())
    .enqueue(new Callback<StatusInfoModel>() {
        @Override
        public void onResponse(Call<StatusInfoModel> call, Response<StatusInfoModel> response) {
            if (response.isSuccessful()) {
                showToast(getApplicationContext(), getString(R.string.new_password_sent));
            } else {
                showToast(getApplicationContext(), getString(R.string.email_not_exist));
            }
        }

        @Override
        public void onFailure(Call<StatusInfoModel> call, Throwable t) {
            showToast(getApplicationContext(), "Something went wrong...");
        }
    });
Run Code Online (Sandbox Code Playgroud)

error-handling android android-studio retrofit2

11
推荐指数
2
解决办法
1万
查看次数

使用FragmentTransaction将数据发送到片段

我在我的片段类中调用它:

@OnClick(R.id.blockedLinkLayout)
public void onBlockedClick(){
    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.content, new SettingsBlockedUsersFragment(), FRAGMENT_TAG);
    ft.commit();
}
Run Code Online (Sandbox Code Playgroud)

它只是用选择的片段替换我当前的片段.

我的问题是,如何String使用FragmentTransaction从我的父片段向我的子片段发送一些数据(例如值)?

android send android-fragments android-bundle fragment-transitions

7
推荐指数
1
解决办法
1万
查看次数

尝试避免向backStack添加两次相同的片段,popBackStackImmediate总是返回false

我正在尝试使用此方法避免向backStack添加相同的片段:

public static void replaceFragment(FragmentManager fragmentManager, Fragment fragment, Boolean addToBackStack) {
        String backStateName = fragment.getClass().getName();
        boolean fragmentPopped = fragmentManager.popBackStackImmediate(backStateName, 0);

        if (addToBackStack && !fragmentPopped && fragmentManager.findFragmentByTag(backStateName) == null) {
            fragmentManager
                    .beginTransaction()
//                    .setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right, android.R.anim.fade_in, android.R.anim.fade_out)
                    .replace(R.id.container, fragment)
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                    .addToBackStack(backStateName) // was 'backStateName'
                    .commit();
        } else {
            if (!addToBackStack)
                fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
            fragmentManager
                    .beginTransaction()
//                    .setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right, android.R.anim.fade_in, android.R.anim.fade_out)
                    .replace(R.id.container, fragment)
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                    .disallowAddToBackStack()
                    .commit();
        }
    }
Run Code Online (Sandbox Code Playgroud)

导航抽屉包含:profilePhoto打开的ImageView和打开的ProfileMainFragment几个类别MainFragmentCategory.Boolean addToBackStackfalse当片段从choosen navigationDrawerMenu并且true …

android android-fragments back-stack android-studio

6
推荐指数
1
解决办法
2945
查看次数

Glide - 后退或调用加载照片时出错的调用方法

Glide - 后退或调用加载照片时出错的调用方法.

嗨!

有没有办法检查Glide来自链接的加载照片或使用fallback/ error何时链接无效或照片不可用?

我的意思是,当Glide不加载照片时,我想调用一种方法(加载其他照片).

这是我的Glide例如:

Glide
        .with(mActivity)
        .load(news.getPagemap().getCseThumbnail().get(0).getSrc())
        .fallback(R.drawable.bg_gradient)
        .error(R.drawable.bg_gradient)
        .centerCrop()
        .crossFade()
        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
        .into(holder.photo);
Run Code Online (Sandbox Code Playgroud)

我试着比较ConstantValues- holder.photo.getDrawable().getConstantState().equals(mActivity.getResources().getDrawable(R.drawable.bg_gradient).getConstantState())但得到了NullPointerException.

android android-studio android-glide

4
推荐指数
2
解决办法
4679
查看次数

选中时单选按钮颜色和文本颜色会发生变化

我怎样才能做到这一点?

在此处输入图片说明

这是我用来更改文本颜色的方法:

maleRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    maleRadioButton.setTextColor(getApplicationContext().getResources().getColor(R.color.colorPrimary));
                } else {
                    maleRadioButton.setTextColor(getApplicationContext().getResources().getColor(R.color.lightGray));
                }
            }
        });
Run Code Online (Sandbox Code Playgroud)

我设置了<item name="android:buttonTint">@color/colorAccent</item>,但是未选中的单选按钮colorAccent不是lightGray

有任何想法吗?

checkbox android colors radio-button android-studio

1
推荐指数
1
解决办法
4729
查看次数