Please help..please help. I am using flip View library in my code.
I am fetching some images from server using retrofit and displaying it on my app using Picasso library.Here I am using a vertical flip library.
When I flip the placeholder images changes to loaded image but when I touch the images it again changes to place holder image.
I tried lot of things..searched internet for whole day..Please any one help..
Here I will submit my full codes
1. Gradle файлы
применить плагин: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.icelab2.flipcart"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
релиз {
minifyEnabled false
proguardFiles getDefaultProguardFile ('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':aphidFlipViewLibrary')
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}
2.Source code of my app
public class MapFragment extends Fragment implements PicInterface.ContentView
{
private FlipViewController flipViewController;
private FlipperAdapter adapter;
PicPresentor picPresentor;
public MapFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_map, container, false);
readDataFromAssets();
flipViewController = (FlipViewController)view.findViewById(R.id.flip_view);
//create and attach adapter to flipper view
return view;
}
//For getting the result from server
//Calling the server and getting the image list
private void readDataFromAssets() {
picPresentor=new PicPresentor(this,new PicModel());
picPresentor.getdata();
}
@Override
public void showPicdetails(String ack, String msg, List<Picdetails> data) {
adapter = new FlipperAdapter((AppCompatActivity) requireActivity(), data);
flipViewController.setAdapter(adapter);
}
@Override
public void emptydetails(String ack, String msg, List<Picdetails> data) {
}
}
//Adapter section.Passing the image list to adapter and by using picasso library loading the image to imageView
3.Adapter
public class FlipperAdapter extends BaseAdapter {
private AppCompatActivity appCompatActivity;
List<Picdetails> data;
private int[] drawableIds = {R.drawable.cat_one,R.drawable.cat_two,R.drawable.cat_three
};
public FlipperAdapter(AppCompatActivity appCompatActivity, List<Picdetails> data) {
super();
this.data = data;
this.appCompatActivity = appCompatActivity;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) appCompatActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// If holder not exist then locate all view from UI file.
if (convertView == null) {
// inflate UI from XML file
convertView = inflater.inflate(R.layout.item_page, parent, false);
// get all UI view
holder = new ViewHolder(convertView);
// set tag for holder
convertView.setTag(holder);
} else {
// if holder created, get tag from view
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(data.get(position).getID());
Picasso.get().load( data.get(position).getImage()).placeholder(R.drawable.boy).into(holder.imageView);
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Picasso.get().load( data.get(position).getImage()).networkPolicy(NetworkPolicy.NO_CACHE).placeholder(R.drawable.boy).into(holder.imageView);
}
});
return convertView;
}
private static class ViewHolder {
private TextView textView;
private ImageView imageView;
public ViewHolder(View v) {
imageView = (ImageView)v.findViewById(R.id.image);
textView = (TextView) v.findViewById(R.id.text);
}
}
}
4.Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:flip="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MapFragment">
<com.aphidmobile.flip.FlipViewController
android:id="@+id/flip_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
flip:orientation="vertical
/>
</LinearLayout>