我的问题是我不知道如何开始使用收到的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) 我想在Retrofit 2.0中处理错误
得到eg code=404
和body=null
,但errorBody()
包含ErrorModel
(Boolean status
和String 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) 我在我的片段类中调用它:
@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
我正在尝试使用此方法避免向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 addToBackStack
是false
当片段从choosen navigationDrawerMenu
并且true …
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
.
我怎样才能做到这一点?
这是我用来更改文本颜色的方法:
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
有任何想法吗?
android ×6
retrofit2 ×2
api ×1
back-stack ×1
checkbox ×1
colors ×1
java ×1
radio-button ×1
retrofit ×1
send ×1