寻呼机片段获得空白的点击事件

时间:2017-06-06 05:22:17

标签: android android-fragments fragmentpageradapter

我已经以编程方式创建了寻呼机片段,我可以在滑动时看到两个片段的视图,但问题是当我在任何片段中执行点击事件时,我的第二个片段变为空白view of fragment on load和{{3 }}

activity code





    public class FullScreenActivity extends AppCompatActivity {
          
      
                InkPageIndicator indicator;
         
           ViewPagerAdapter adapter;
           
         Handler handler;
             
       Timer timer;
              
      Runnable runnable;
             
       FragmentManager frgManager;
            
        FragmentTransaction frgTransaction;
        
            Fragment fragment;
            
        private ContextMenuDialogFragment mMenuDialogFragment;
          
          CoordinatorLayout main_content;
          
          private MyFragmentPagerAdapter mMyFragmentPagerAdapter;
         
           ViewPager mViewPager;
            
        private Toolbar toolbar;
          
          private String catId;
            
        private String mode;
          
          private int matrix_count;
           
         private int matrix_position;
         
           private String sort;
              
      private String productId;
            
        private ArrayList<Products> productList = new ArrayList<Products>();
                private String table = "";
            
        private NetworkCommunication net;
            
        private int data = 10;
               
     private String catalogueId = "",
     orderId = "";
               
     private TextView mTitle;
        
            private String product_id = "";
             
       private int navigationBg, navigationfg, bottombarbg, bottombarfg;
                private String itemCode;
               
     private HashMap<String, String> filterSendMap;
         
           private String id = "";
             
       private ArrayList<Cart.Product> cartProductList;
          
          private ArrayList<Cart.Product> checkboxes;
            
        private String cartId = "";
               
     private String whichMaster = "";
              
      private ArrayList<String> catalogue_keys;
          
      
                
                @Override
            
        public void onCreate(Bundle savedInstanceState) {
          
              super.onCreate(savedInstanceState);
            
    
                    if (SingletonClass.getinstance() != null)
            
            if 
    (SingletonClass.getinstance().screenshot.equalsIgnoreCase("not_allowed")) {
                        
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
             
           }
                    
    setContentView(R.layout.activity_full_screen);
            
           
             if (SingletonClass.getinstance() != null)
           
                 defineColors();
                
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        Window window = getWindow();
                        
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
               
             window.setNavigationBarColor(navigationBg);
          
                  window.setStatusBarColor(navigationBg);
          
              }
                    toolbar = (Toolbar) findViewById(R.id.toolbar);
                    mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
          
              setSupportActionBar(toolbar);
                    toolbar.setBackgroundColor(navigationBg);
                
        mTitle.setTextColor(navigationfg);
            
              
          Drawable back = getResources().getDrawable(R.drawable.ic_back);
            
                    // colors
            
               
         int color = getResources().getColor(R.color.textColorPrimary);
                    back.setColorFilter(navigationfg, PorterDuff.Mode.SRC_ATOP);
                    toolbar.setNavigationIcon(back);
                    
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
         
                   @Override
                      
      public void onClick(View v) {
             
                   onBackPressed();
               
             }
                 
       });
            
            
                
        Intent intent = getIntent();
             
           if (intent != null) {
              
              mode = intent.getStringExtra("mode");
               
             catId = intent.getStringExtra("cat_id");
                        productId = intent.getStringExtra("product_id");
           
     //            list = intent.getParcelableArrayListExtra("list");
                        matrix_count = intent.getIntExtra("matrix_count", 0);
            
                sort = intent.getStringExtra("sort");
                        matrix_position = intent.getIntExtra("matrix_position", 0);
                        catalogueId = intent.getStringExtra("catalogue_id");
                        orderId = intent.getStringExtra("order_id");
           
                 id = intent.getStringExtra("id");
         
                   whichMaster = intent.getStringExtra("which_master");
                        filterSendMap = (HashMap<String, String>) intent.getSerializableExtra("filter_data");
           
                 if (mode.equals("UpdateCart")) {
          
                      product_id = intent.getStringExtra("product_id");
    
                            cartId = intent.getStringExtra("id");
            
                    cartProductList = 
    intent.getParcelableArrayListExtra("product_list");
          
                      checkboxes = intent.getParcelableArrayListExtra("checkboxes");
                            catalogue_keys = intent.getStringArrayListExtra("catalogue_keys");
          
                  }
            
               
             Log.d("In FullScreen Activity", "mode :: " + mode);
            
                           }
            
             
          intent = new Intent(FullScreenActivity.this, MyService.class);
            
                    if (isMyServiceRunning(MyService.class, this)) {
            
                stopService(intent);
                        intent.putExtra("ScreenName", "Cart");
                        intent.putExtra("ProductId", productId);
                        intent.putExtra("Model", Build.MODEL);
                        startService(intent);
                    }
     else {
            
                    
        intent.putExtra("ScreenName", "Cart");
                        intent.putExtra("ProductId", productId);
                        intent.putExtra("Model", Build.MODEL);
                        startService(intent);
                  
      }
            
            
            
               
         mViewPager = (ViewPager) findViewById(R.id.pager);
            
                    net = new NetworkCommunication(this);
           
             ConnectionDetector cd = new ConnectionDetector(this);
                    cd.isConnectingToInternet();
               
         if (!cd.isConnectingToInternet()) {
                
            runOnUiThread(new Runnable() {
                       
         public void run() {
                           
         showAlertDialog(FullScreenActivity.this, "Internet Connection", "You dont have internet connection", true);
                            }
                        });
              
          } else {
           
                 table = "design_master"
           
     
                }
            
            
        @Override
             
       public void onBackPressed() {
                  
      Fragment selectedFragment = getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":" + mViewPager.getCurrentItem());
           
             // based on the current position you can then cast the page to the correct
                    // class and call the method:
           
             FullScreenFragment ffragment = (FullScreenFragment) fragment;
                    if (selectedFragment.equals(ffragment)
     && ffragment.hasExpandedSheet())
     {
                     
       ffragment.collapseSheet();
             
           } else {
                
            // handle by activity
                 
           super.onBackPressed();
            
            }
                }
            
            
        
        
            
                public class FetchFullScreenTask extends AsyncTask<Void, Void, ArrayList<Products>> {
           
             ArrayList<Products> list = null;
              
          private ProgressDialog pdg;
            
          

              @Override
                 
       protected void onPreExecute() {
           
                 super.onPreExecute();
                
            pdg = ShowProgressDialog();
            
                 
       }
            
                 
       @Override
                
        protected ArrayList<Products> doInBackground(Void... params) {
         
                   list = 
    net.fetchFullScreen(SingletonClass.getinstance().userId, productId, table, mode, catId, sort, "" + matrix_position, "" + data, catalogueId, orderId, filterSendMap, whichMaster);
            //       
         currentPage = currentPage + 1;
            
        
                    return list;
                    }
            
        

         @Override
               
         public void onPostExecute(ArrayList<Products> data) {
                        Log.d("FetchFullScreenTask", "Running");
               
             pdg.dismiss();
               
             productList = data;
                        //Log.wtf("!!!1", "listsize" + productList.size());
            
            //            if (productList.size() >= matrix_position) {
                        Log.wtf("!!!1", "listsize" + productList.size());
           
                 mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), productList, sort, matrix_position, catalogueId, catalogue_keys, whichMaster);
                        mViewPager.setAdapter(mMyFragmentPagerAdapter);
                        mMyFragmentPagerAdapter.notifyDataSetChanged();
                        mViewPager.setOffscreenPageLimit(1);
                        mViewPager.setCurrentItem(matrix_position);
            //     
           }
              
          }
             
       }
            
            
            //pager adapter
            
             
       private class MyFragmentPagerAdapter extends FragmentPagerAdapter {
            
                    private String whichMaster = "";
           
             private String sortmode, catalogueId;
         
               private int page, myc_id;
              
          private ArrayList<Products> productList;
         
               private ArrayList<String> catalogue_keys;
            
    
                    public MyFragmentPagerAdapter(FragmentManager fm, ArrayList<Products> productList, String sortMode,
                                                  int page, String catalogueId, ArrayList<String> catalogue_keys, String whichMaster) {
              
              super(fm);
                   
         this.productList = productList;
             
               this.catalogue_keys = catalogue_keys;
                        this.sortmode = sortMode;
                     
       this.page = page;
                      
      this.catalogueId = catalogueId;
           
                 this.whichMaster = whichMaster;
        
                    Log.d("In Adapter", "page :: " + page);
                        Log.d("In Adapter", "mode :: " + mode);
             
               Log.d("In Adapter", "whichMaster :: " + whichMaster);
                    }
            
                    @Override
                    public Fragment getItem(int position) {
                        // position = this.page;
                        if (mode.equals("simple") || mode.equals("homescreen") || mode.equals("my_catalogue") ||
                                mode.equals("filter") || mode.equals("UpdateCart") || mode.equals("all") ||
                                mode.equals("catalogue_filter") || mode.equals("all_filter") ||
                                mode.equals("order_filter") || mode.equals("order") || mode.equals("all_past_orders") ||
                                mode.equals("all_past_orders_filter")) {
                            frgManager = getSupportFragmentManager();
                            fragment = new FullScreenFragment(FullScreenActivity.this, mode, catId, productList, matrix_count, matrix_position, sort, catalogueId,
                                    id, product_id, cartProductList, checkboxes, cartId, catalogue_keys, whichMaster);
                            return fragment;
                        } else {
                            Log.d("In FullScreenActivity", "mode :: " + mode);
                            return null;
           
             }
         
           }
            
              
      @Override
                    public int getCount() {
                        if (mode.equals("simple") || mode.equals("homescreen") || mode.equals("my_catalogue") ||
                                mode.equals("filter") || mode.equals("UpdateCart") || mode.equals("all") ||
               
               mode.equals("catalogue_filter") || mode.equals("all_filter") ||
                                mode.equals("order_filter") || mode.equals("order") || mode.equals("all_past_orders") ||
                                mode.equals("all_past_orders_filter")) {
            //                return matrix_count;
            //            } else if (mode.equals("homescreen") || mode.equals("UpdateCart")) {
          
                  return 1;
         
   //            } else if (mode.equals("filter")) {
       
     //                return productList.size();
        
                } else {
       
                     return -1;
        
                }
                 
   }
            
              
  }
            
           
 
                @Override
       
         protected void onDestroy() {
      
              // TODO Auto-generated method stub
                    super.onStop();
                 
   stopService(new Intent(this, MyService.class));
        
    
                }
            
            
          
      @NonNull
               
 private ProgressDialog ShowProgressDialog() {
              
      int navigationBg = Color.rgb(parseInt((SingletonClass.getinstance().fetchNavBgColor())[0].trim()),
              
                  parseInt((SingletonClass.getinstance().fetchNavBgColor())[1].trim()),
                            parseInt((SingletonClass.getinstance().fetchNavBgColor())[2].trim()));
            
     DisplayMetrics displaymetrics = new DisplayMetrics();
                    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
                    int height = displaymetrics.heightPixels;
              
      int width = displaymetrics.widthPixels;
            
                    final ProgressDialog pdg = new ProgressDialog(this);
                    pdg.setMessage("please wait...");
                    pdg.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    pdg.show();
                 
   Window window = pdg.getWindow();
          
          window.setLayout(width / 3, width / 3);
                    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    window.setContentView(R.layout.progress_loader);
            
                    ImageView imgLoader = (ImageView) window.findViewById(R.id.progress_loader);
                    imgLoader.getDrawable().setColorFilter(navigationBg, PorterDuff.Mode.SRC_ATOP);
            //        // load the animation
            //        Animation animFadein = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_left);
            //        imgLoader.startAnimation(animFadein);
                    pdg.setCancelable(false);
      
              return pdg;
       
         }
            
              

  public void showAlertDialog(Context context, String title, String message, Boolean status) {
         

           AlertDialog alertDialog = new AlertDialog.Builder(context).create();
                    alertDialog.setTitle(title);
                    alertDialog.setMessage(message);
            
                    Drawable alert = context.getResources().getDrawable(android.R.drawable.ic_dialog_alert);
                    alert.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
                    alertDialog.setIcon(alert);
            
                    alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Close", new DialogInterface.OnClickListener() {
       
                 public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
             
               System.exit(1);

                        }
              
      });
                  
  alertDialog.show();
        
        }
            
            

            }

  CODE OF PAGER AND FRAGMENTS



     public class SubProductPagerAdapter extends FragmentPagerAdapter {
            
            
            public SubProductPagerAdapter(FragmentManager fm) {
              
              super(fm);
              
              fragementList = new ArrayList<Fragment>();
               
             if (product != null)
                  
              Log.i("FullScreenFragment", "subProductCount = " + product.subProductCount);
              
              else
                    
            Log.i("FullScreenFragment", "Product = " + product);
             
           }
            
              

          @Override
                public int getCount() {
              
              if (product != null) {
                
                return product.subProductCount + 1;
              
              } else {
                 
                  return 0;
                 
               //return 1;
                 
           }
               
         }
            
               

         @Override
               
         public Fragment getItem(int position) {
              

              Fragment fragment = null;
               
             //  subProductCheckedList==null? ArrayList<boolean> subProductCheckedList.add(true) : subProductCheckedList;
             
               if (product != null)
                
                if (position == 0) {
                
                    if (mode.equalsIgnoreCase("UpdateCart"))
            
                                fragment = SubProductFragment.newInstance(product, position, cartProductList.get(position).product_id,
                                        cartProductList.get(position).grossWt, cartProductList.get(position).netWt, cartProductList.get(position).karat,
                                        cartProductList.get(position).diamond, cartProductList.get(position).sizee, cartProductList.get(position).piece,
                                        cartProductList.get(position).quantity, cartProductList.get(position).remarks, cartProductList.get(position).tone,
                                        cartProductList.get(position).certi, cartProductList.get(position).hallmark, subProductCheckedList);
                            else
                        
                fragment = SubProductFragment.newInstance(product, position, product_id, null, null, null, null, null, null, null, null, null, null, null, null);
                   
             } else {
               
                     if (mode.equalsIgnoreCase("UpdateCart"))
                                fragment = SubProductFragment.newInstance(product.subProductList.get(position - 1), position, cartProductList.get(position).product_id,
                                        cartProductList.get(position).grossWt, cartProductList.get(position).netWt, cartProductList.get(position).karat,
                                        cartProductList.get(position).diamond, cartProductList.get(position).sizee, cartProductList.get(position).piece,
                                        cartProductList.get(position).quantity, cartProductList.get(position).remarks, cartProductList.get(position).tone,
                                        cartProductList.get(position).certi, cartProductList.get(position).hallmark, subProductCheckedList);
                            else
                           
             fragment = SubProductFragment.newInstance(product.subProductList.get(position - 1), position, product_id, null, null, null, null, null, null, null, null, null, null, null, null);
                     
           }
                 
           fragementList.add(fragment);
            
                
            return fragment;
                }
            
            
            @Override
                public CharSequence getPageTitle(int position) {
                    if (product != null) {
                 
               if (position == 0) {
                
                    return product.category_name;
                    
            } else {
                        
            return product.subProductList.get(position - 1).category_name;
                        }
                 
           } else {
              
                  return "";
               
             }
              
          }
        
            
            }


        public static class SubProductFragment extends Fragment {

        static SubProductFragment newInstance(Products product, int position, String product_id,
                                                  String gross_wt, String net_wt, String karat, String diamond,
                                                  String size, String piece, String quantityy, String remarks, String tone,
                                                  String certification, String hallmark, ArrayList<Boolean> subProductCheckedList)

         {
               
         SubProductFragment f = new SubProductFragment();
             
           Bundle args = new Bundle();
               
         args.putInt("page", position);
              
          args.putParcelable("product", product);
             
           if (mode.equals("UpdateCart")) {
               
             args.putString("product_id", product_id);
                    args.putString("gross_wt", gross_wt);
               
             args.putString("net_wt", net_wt);
              
              args.putString("karat", karat);
              
              args.putString("diamond", diamond);
        
                    args.putString("size", size);
                
            args.putString("piece", piece);
                
            args.putString("tone", tone);
                  
          args.putString("quantityy", quantityy);
                    args.putString("remarks", remarks);
                
            args.putString("certi", certification);
                    args.putString("hallmark", hallmark);
                    args.putSerializable("productcheckedlist", subProductCheckedList);
              
          }
              
          f.setArguments(args);
            
              
          return f;
       
 }


        @Override
             
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
         {
                
        return inflater.inflate(R.layout.fragment_product_details, container, false);
        
            }
            
            

        @Override
            public void onViewCreated(View view, Bundle savedInstanceState) {
             
           super.onActivityCreated(savedInstanceState);
               
         initialize(view, page);
             
           try {
                 
           setData(product, page);
        
            
                } catch (Exception e) 
        {
                    e.printStackTrace();
             
           }
            
        }


        }
       

logcat的

06-06 11:17:33.373 19842-19842/com.triologic.jewelflowpro.vivaaz I/Choreographer: Skipped 36 frames!  The application may be doing too much work on its main thread.
06-06 11:17:47.060 19842-19842/com.triologic.jewelflowpro.vivaaz D/PageIndicator: dot 1 fraction:   1.0
06-06 11:17:47.235 19842-19852/com.triologic.jewelflowpro.vivaaz W/art: Suspending all threads took: 5.442ms
06-06 11:17:59.203 19842-19842/com.triologic.jewelflowpro.vivaaz V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@de18b72
06-06 11:17:59.204 19842-19842/com.triologic.jewelflowpro.vivaaz V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@db14bc3
06-06 11:17:59.286 19842-19842/com.triologic.jewelflowpro.vivaaz V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@aecd89c
06-06 11:17:59.286 19842-19842/com.triologic.jewelflowpro.vivaaz V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@57ff2a5
06-06 11:18:02.673 19842-19976/com.triologic.jewelflowpro.vivaaz D/OpenGLRenderer: endAllActiveAnimators on 0x7f77452400 (RippleDrawable) with handle 0x7f98048540
06-06 11:18:08.072 19842-19842/com.triologic.jewelflowpro.vivaaz D/PageIndicator: dot 1 fraction:   1.0
06-06 11:18:29.072 19842-19842/com.triologic.jewelflowpro.vivaaz D/PageIndicator: dot 1 fraction:   1.0
06-06 11:18:50.702 19842-19842/com.triologic.jewelflowpro.vivaaz D/PageIndicator: dot 1 fraction:   1.0
06-06 11:19:02.727 19842-22602/com.triologic.jewelflowpro.vivaaz V/FA: Activity paused, time: 218137259
06-06 11:19:03.733 19842-22602/com.triologic.jewelflowpro.vivaaz D/FA: Application backgrounded. Logging engagement
06-06 11:19:03.761 19842-22602/com.triologic.jewelflowpro.vivaaz I/DynamiteModule: Considering local module com.google.android.gms.tagmanager:1 and remote module com.google.android.gms.tagmanager:9
06-06 11:19:03.761 19842-22602/com.triologic.jewelflowpro.vivaaz I/DynamiteModule: Selected remote version of com.google.android.gms.tagmanager, version >= 9
06-06 11:19:03.829 19842-22602/com.triologic.jewelflowpro.vivaaz W/GoogleTagManager: No container asset found in /assets/containers. Checking top level /assets directory for container assets.
06-06 11:19:03.840 19842-22602/com.triologic.jewelflowpro.vivaaz W/GoogleTagManager: Tag Manager's event handler WILL NOT be installed (no container loaded)
06-06 11:19:03.840 19842-22602/com.triologic.jewelflowpro.vivaaz I/GoogleTagManager: Tag Manager initilization took 26ms
06-06 11:19:03.851 19842-22602/com.triologic.jewelflowpro.vivaaz D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=102992}]
06-06 11:19:03.852 19842-22602/com.triologic.jewelflowpro.vivaaz V/FA: Using measurement service
06-06 11:19:03.852 19842-22602/com.triologic.jewelflowpro.vivaaz V/FA: Connecting to remote service
06-06 11:19:03.862 19842-22602/com.triologic.jewelflowpro.vivaaz D/FA: Connected to remote service
06-06 11:19:03.863 19842-22602/com.triologic.jewelflowpro.vivaaz V/FA: Processing queued up service tasks: 1
06-06 11:19:08.871 19842-22602/com.triologic.jewelflowpro.vivaaz V/FA: Inactivity, disconnecting from AppMeasurementService
06-06 11:19:11.717 19842-19842/com.triologic.jewelflowpro.vivaaz D/PageIndicator: dot 1 fraction:   1.0
06-06 11:19:32.716 19842-19842/com.triologic.jewelflowpro.vivaaz D/PageIndicator: dot 1 fraction:   1.0
06-06 11:19:53.719 19842-19842/com.triologic.jewelflowpro.vivaaz D/PageIndicator: dot 1 fraction:   1.0

0 个答案:

没有答案