Created
February 10, 2016 11:54
-
-
Save ashu2121/c88e91a52d773cb0dd4f to your computer and use it in GitHub Desktop.
View Pager is not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Context; | |
| import android.support.v4.view.PagerAdapter; | |
| import android.util.Log; | |
| import android.view.LayoutInflater; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.ImageView; | |
| import android.widget.RelativeLayout; | |
| import android.widget.TextView; | |
| import com.squareup.picasso.MemoryPolicy; | |
| import com.squareup.picasso.Picasso; | |
| import java.util.ArrayList; | |
| import java.util.HashMap; | |
| import info.androidhive.slidingmenu.R; | |
| import info.androidhive.slidingmenu.library.Global_JsonTags; | |
| public class News_Adapter extends PagerAdapter | |
| { | |
| Context mContext; | |
| Global_JsonTags jsontags = new Global_JsonTags(); | |
| LayoutInflater inflater; | |
| LayoutInflater mLayoutInflater; | |
| //using abc for testing | |
| String[] abc = {"a","b","c"}; | |
| // ArrayList<HashMap<String, String>> home_news_arrays = new ArrayList<HashMap<String, String>>(); | |
| // contsructor | |
| public News_Adapter(Context context, ArrayList<HashMap<String, String>> home_news_array) { | |
| mContext = context; | |
| home_news_arrays = new ArrayList<HashMap<String, String>>(home_news_array); | |
| mLayoutInflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE); | |
| } | |
| @Override | |
| public int getCount() { | |
| return abc.length; | |
| } | |
| @Override | |
| public boolean isViewFromObject(View view, Object object) { | |
| return view == ((RelativeLayout) object); | |
| } | |
| @Override | |
| public Object instantiateItem(ViewGroup container, int position) { | |
| inflater = (LayoutInflater) mContext | |
| .getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
| View itemView = inflater.inflate(R.layout.news, container, false); | |
| //getting views | |
| ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView54); | |
| TextView news_title = (TextView) itemView.findViewById(R.id.news_title); | |
| TextView news_date = (TextView) itemView.findViewById(R.id.home_new_date); | |
| TextView news_descrition = (TextView) itemView.findViewById(R.id.home_news_description); | |
| // maping values | |
| Log.d(" News home_news_array ", home_news_arrays.get(position).get("product_name")); | |
| news_title.setText("working"); | |
| news_date.setText("working"); | |
| news_descrition.setText(home_news_arrays.get(position).get(jsontags.home_news_description)); | |
| Picasso.with(mContext) | |
| .load(home_news_arrays.get(position).get("product_image")) | |
| .placeholder(R.drawable.ic_stub) // optional | |
| .error(R.drawable.ic_error) // optional | |
| .fit() | |
| .centerCrop() | |
| .memoryPolicy(MemoryPolicy.NO_CACHE) | |
| .into(imageView); | |
| container.addView(itemView); | |
| return itemView; | |
| } | |
| @Override | |
| public void destroyItem(ViewGroup container, int position, Object object) { | |
| container.removeView((RelativeLayout) object); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment