我正在使用Retrofit下载产品列表(JSON),然后我将收到的数据设置到我的回收站视图。
但是当我在回收者视图上快速滚动时,当前片段(回收者视图的容器)将被关闭,我将进入主要活动。我的logCat没有错误。
这是我设置回收站视图和改造的片段:
private RecyclerView singleListRecycler;
private RecyclerView.LayoutManager rtlGridLayoutManager;
private RecyclerView.Adapter weekAdapter;
private List<PList> singleList = new ArrayList<PList>();
private String prgCode;
private LinearLayout layoutLoading;
private TextView txtNoGood;
int totalPage = 1;
int currentPage = 1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_product, container, false);
inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
syncBasket();
user_auth = G.getPremiumState()[0];
user_pass = G.getPremiumState()[1];
user_mobile = G.getPremiumState()[2];
if (user_auth.equals("") || user_mobile.equals("") || user_pass.equals("")) {
Toast.makeText(getContext(), "خطایی رخ داده است ! مجدد تلاش کنید.", Toast.LENGTH_SHORT).show();
Intent goToStartup = new Intent(getContext(), ActivityStartup.class);
getActivity().finish();
startActivity(goToStartup);
}
singleListRecycler = (RecyclerView) view.findViewById(R.id.singleListRecycler);
layoutLoading = (LinearLayout) view.findViewById(R.id.layout_loading);
txtNoGood = (TextView) view.findViewById(R.id.txt_no_good);
Bundle bundle = getActivity().getIntent().getExtras();
if (bundle != null) {
prgCode = bundle.getString("PRG_CODE");
} else {
Intent goBack = new Intent(getContext(), ActivityMainProducts.class);
startActivity(goBack);
}
//Preparing data from server for this group
getSingleGroup(prgCode, currentPage);
//Add Two Listener to RecyclerView
singleListRecycler.addOnScrollListener(new PicassoOnScrollListener(context));
singleListRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy < 0) {
// Recycle view scrolling up ...
// Toast.makeText(activitySingleGroup, "Top", Toast.LENGTH_SHORT).show();
} else if (dy > 0) {
if (!singleListRecycler.canScrollVertically(View.SCROLL_AXIS_VERTICAL)) {
currentPage = currentPage + 1;
if (currentPage > totalPage) {
currentPage = totalPage;
layoutLoading.setVisibility(View.GONE);
} else {
layoutLoading.setVisibility(View.VISIBLE);
getSingleGroup(prgCode, currentPage);
}
}
}
}
});
return view;
}
private void getSingleGroup(String code, int page) {
if (singleList.size() == 0) {
G.showProgress(getActivity());
}
APIService apiService = ServiceGenerator.createService(APIService.class, user_auth, user_pass);
String url = "prg/" + code + "/" + page;
Call<ProductModel> call = apiService.getNormalList(url);
call.enqueue(new Callback<ProductModel>() {
@Override
public void onResponse(Call<ProductModel> call, Response<ProductModel> response) {
layoutLoading.setVisibility(View.GONE);
Log.i("LOGO", "Code of Normal is: " + response.code());
if (singleList.size() == 0) {
G.dismissProgress();
}
if (response.code() == 200) {
ProductModel newMainCategory = response.body();
totalPage = newMainCategory.getPTotalPage();
singleList.addAll(newMainCategory.getPList());
rtlGridLayoutManager = new RtlGridLayoutManager(getContext(), 1);
singleListRecycler.setLayoutManager(rtlGridLayoutManager);
weekAdapter = new BaseListAdapter(singleList, (ActivitySingleGroup) getActivity());
if (singleList.size() > 0) {
singleListRecycler.setAdapter(weekAdapter);
} else {
singleListRecycler.setVisibility(View.GONE);
txtNoGood.setVisibility(View.VISIBLE);
}
} else {
singleListRecycler.setVisibility(View.GONE);
txtNoGood.setVisibility(View.VISIBLE);
}
}
@Override
public void onFailure(Call<ProductModel> call, Throwable t) {
Log.i("LOGO", "Error s: " + t.toString());
if (singleList.size() == 0) {
G.dismissProgress();
}
layoutLoading.setVisibility(View.GONE);
singleListRecycler.setVisibility(View.GONE);
txtNoGood.setVisibility(View.VISIBLE);
}
});
}
这是recyclerView的适配器:
public class BaseListAdapter extends RecyclerView.Adapter<BaseListAdapter.ViewHolder> {
private List<PList> menuItems;
private Context mContext;
private ActivitySingleGroup activitySingleGroup;
private int lastPosition = -1;
public BaseListAdapter(List<PList> menuItems, Context mContext) {
this.menuItems = menuItems;
this.mContext = mContext;
this.activitySingleGroup = (ActivitySingleGroup) mContext;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView txtName;
TextView txtPrice;
ImageView imgDefault;
LinearLayout parentLayout;
CoordinatorLayout coordinatorLayout;
public ViewHolder(View v) {
super(v);
txtName = (TextView) v.findViewById(R.id.txtName);
txtPrice = (TextView) v.findViewById(R.id.txtPrice);
imgDefault = (ImageView) v.findViewById(R.id.img_defaultImage);
parentLayout = (LinearLayout) v.findViewById(R.id.parentLayout);
coordinatorLayout = (CoordinatorLayout) v.findViewById(R.id.coordinatorLayout);
}
}
@Override
public BaseListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new View
final View v = LayoutInflater.from(activitySingleGroup).inflate(R.layout.activity_normal_group_recycler, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
//Download and Load Default Image from server into imgDefault ImageView
Picasso picasso;
OkHttpClient client = null;
String url = "https://bartarinapp-irdeveloper.rhcloud.com/api/images/download/";
//Handel situations that default image variables will be null
if (menuItems.get(position).getPDefaultImage() != null &&
menuItems.get(position).getPDefaultImage().getDefault() != null) {
if ((menuItems.get(position).getPDefaultImage().getDefault()) &&
(menuItems.get(position).getPDefaultImage().getIId() != null)) {
url += menuItems.get(position).getPDefaultImage().getIId();
client = ServerClass.setAuthImage();
picasso = new Picasso.Builder(mContext)
.downloader(new OkHttp3Downloader(client))
.listener(new Picasso.Listener() {
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
//Here your log
Log.i("I_ERROR", "Error is: " + exception.toString());
}
})
.build();
} else {
url = null;
picasso = new Picasso.Builder(mContext)
.listener(new Picasso.Listener() {
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
//Here your log
Log.i("I_ERROR", "Error is: " + exception.toString());
}
})
.build();
}
} else {
url = null;
picasso = new Picasso.Builder(mContext)
.listener(new Picasso.Listener() {
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
//Here your log
Log.i("I_ERROR", "Error is: " + exception.toString());
}
})
.build();
}
picasso.cancelRequest(holder.imgDefault);
if (url != null && url.length() > 0) {
//put here picaso image load code
picasso.load(url)
.tag(PicassoOnScrollListener.TAG)
.placeholder(R.drawable.loading_01)
.error(R.drawable.loading_02)
.into(holder.imgDefault);
} else {
holder.imgDefault.setImageResource(R.drawable.ic_empty_white_box);
}
holder.txtName.setText(menuItems.get(position).getPName());
holder.txtPrice.setText(String.valueOf(menuItems.get(position).getPPrice()));
holder.parentLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
prepareBottomSheet(view, position, holder.coordinatorLayout);
}
});
}
@Override
public int getItemCount() {
if (menuItems.size() > 0) {
return menuItems.size();
} else {
return 0;
}
}
我在回收者视图中使用了毕加索。我不知道这里发生了什么! 这是我的logCat,当应用程序将关闭当前片段或有时会崩溃。
这是我的logCat:
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzapn;
at com.google.android.gms.internal.zzbku.<clinit>(Unknown Source)
at com.google.android.gms.internal.zzbku.initialize(Unknown Source)
at com.google.firebase.crash.FirebaseCrash.getInstance(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzapn" on path: DexPathList[[zip file "/data/app/codenevisha.com.apps.bartarinapp-1/base.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_dependencies_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_0_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_1_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_2_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_3_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_4_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_5_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_6_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_7_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_8_apk.apk",
zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_9_apk.apk"],
nativeLibraryDirectories=[/data/app/codenevisha.com.apps.bartarinapp-1/lib/arm, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.android.gms.internal.zzbku.<clinit>(Unknown Source)
at com.google.android.gms.internal.zzbku.initialize(Unknown Source)
at com.google.firebase.crash.FirebaseCrash.getInstance(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "codenevisha.com.apps.bartarinapp"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:cardview-v7:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'me.relex:circleindicator:1.2.2@aar'
//Retrofit & GSon
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.retrofit2:converter-scalars:2.3.0'
//Google Services of location
compile 'com.google.android.gms:play-services-location:11.0.1'
//Picasso
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5@aar'
//Pretty Log
compile 'com.orhanobut:logger:2.1.1'
//Fire base
compile 'com.google.firebase:firebase-crash:10.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.github.manuelpeinado.fadingactionbar:fadingactionbar:3.1.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
感谢您的回答。
答案 0 :(得分:1)
看起来您正在使用不同的库版本。
请提供您的build.gradle文件。