Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Home extends Fragment{
- ViewPager home_news;
- ArrayList<HashMap<String, String>> home_news_array = new ArrayList<HashMap<String, String>>();
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- rootview = inflater.inflate(R.layout.content_navigation_drawer, container, false);
- if (android.os.Build.VERSION.SDK_INT > 9) {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- }
- View homenews = rootview.findViewById(R.id.home_news);
- home_news = (ViewPager)homenews.findViewById(R.id.viewpager);
- Homenews_Jsons homenewsjson = new Homenews_Jsons();
- homenewsjson.execute();
- News_Adapter newsviewpager = new News_Adapter(getActivity(), home_news_array);
- home_news.setAdapter(newsviewpager);
- return rootview
- }
- private class Homenews_Jsons extends AsyncTask<ArrayList<HashMap<String, String>>, Void, ArrayList<HashMap<String, String>>> {
- private ProgressDialog dialog = new ProgressDialog(getActivity());
- @Override
- protected ArrayList<HashMap<String, String>> doInBackground(ArrayList<HashMap<String, String>>... params) {
- try {
- JSONArray data = new JSONArray(lib_function.getJSONUrl( jsontags.HOME_NEWS_JOSN_URL));
- HashMap<String, String> home_news_map;
- for (int i = 0; i < data.length(); i++) {
- JSONObject c = data.getJSONObject(i);
- home_news_map = new HashMap<String, String>();
- home_news_map.put(jsontags.home_news_name, c.getString("s"));
- home_news_map.put(jsontags.home_news_image, c.getString("price"));
- home_news_map.put(jsontags.home_news_description, c.getString("thumb"));
- home_news_map.put(jsontags.home_news_id, c.getString("product_id"));
- home_news_map.put(jsontags.home_news_date, c.getString("product_id"));
- home_news_array.add(home_news_map);
- // liustitemsa = best_prpduct_array.size()-1;
- Log.d("home news ", "" + home_news_array);
- // checking website is workign or not
- // if json return values is equuals to 0 then all further work will stop and show error
- if(best_prpduct_array.size() >=1)
- {
- check_website_working = 1;
- }
- else {}
- }
- best_scuuess=1;
- Log.d("home news suceesss " ,""+best_scuuess);
- Log.d("home news complete", "home news complete donwload");
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return best_prpduct_array;
- }
- @Override
- protected void onPreExecute() {
- spinner.setVisibility(View.VISIBLE);
- Log.d("starting DialogBox", "starting DialogBox");
- super.onPreExecute();
- }
- // for run mail thread UI
- protected void publishProgress() {
- }
- @Override
- protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
- super.onPostExecute(result);
- }
- }
- }
- //=====================================================================================//
- NewsAdapter Class
- public class News_Adapter extends PagerAdapter{
- Context mContext;
- Global_JsonTags jsontags = new Global_JsonTags();
- LayoutInflater inflater;
- LayoutInflater mLayoutInflater;
- 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;
- mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- home_news_arrays = new ArrayList<HashMap<String, String>>(home_news_array);
- //home_news_arrays=home_news_array;
- Log.d(" News Apdater items" ,"-----------------------------------------------------------------------------------------------------");
- }
- @Override
- public int getCount() {
- Log.d(" News Apdater items" ,""+abc.length);
- return abc.length;
- }
- @Override
- public boolean isViewFromObject(View view, Object object) {
- return view == ((RelativeLayout) object);
- }
- @Override
- public Object instantiateItem(ViewGroup container, int position) {
- View itemView = null;
- try {
- inflater = (LayoutInflater) mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- itemView = inflater.inflate(R.layout.news, container, false);
- Log.d("View created -------------------------------------------------------------------","View created");
- }catch (Exception e) {Log.d("Error------------------------------------------------------",""+e);}
- //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);
- Log.d("values in Adapter----------",abc[position]);
- // maping values
- /*
- Log.d(" News home_news_array ", home_news_arrays.get(position).get("product_name"));
- */
- news_title.setText(abc[position]);
- news_date.setText(abc[position]);
- /* 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) // optionals
- .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);
- }
- }
Add Comment
Please, Sign In to add comment