a.g.thamays a.g.thamays - 3 months ago 27
Android Question

How to design android pop-up window with likely slide list view

likely this design ,

pop-up window with likely slide list view
if click arrow button move to next view

please give any ideas with coding...

enter image description here

Answer

i created likely that.. coding & reference here

view pager reference

  1. pop up window java code

    public void popUpWindow() {
    
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.activity_main_investment_popup_pageadapter);
    
    dotsLayout = (LinearLayout) dialog.findViewById(R.id.layoutDots1);
    btnPrevious = (ImageButton) dialog.findViewById(R.id.btnPrevious);
    btnNext = (ImageButton) dialog.findViewById(R.id.btnNext);
    popUpClose = (ImageButton) dialog.findViewById(R.id.popUpClose);
    
    // adding bottom dots
    addBottomDots(0);
    
    viewPager = (ViewPager) dialog.findViewById(R.id.pager_popUP);
    // Pass results to ViewPagerAdapter Class
    adapter = new ViewPagerAdapter(context, list, ListTotalReturnPrice, population);
    // Binds the Adapter to the ViewPager
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(viewPagerPageChangeListener);
    
    dialog.show();
    
    btnNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int current = getSlideItem(+1);
            viewPager.setCurrentItem(current);
        }
    });
    
    btnPrevious.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // checking for last page
            // if last page home screen will be launched
            int current = getSlideItem(-1);
            viewPager.setCurrentItem(current);
        }
    });
    
    popUpClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          dialog.cancel();
        }
    });
    
    }
    
    private int getSlideItem(int i) {
    return viewPager.getCurrentItem() + i;
    }
    
    private void addBottomDots(int currentPage) {
    dots = new TextView[list.size()];
    
    int colorsActive = Color.rgb(65, 87, 147);
    int colorsInactive = Color.rgb(217, 217, 217);
    
    dotsLayout.removeAllViews();
    for (int i = 0; i < dots.length; i++) {
        dots[i] = new TextView(context);
        dots[i].setText(Html.fromHtml("&#8226;"));
        dots[i].setTextSize(35);
        dots[i].setTextColor(colorsInactive);
        dotsLayout.addView(dots[i]);
    }
    
    if (dots.length > 0)
        dots[currentPage].setTextColor(colorsActive);
    }
    

2.viewpager change listener

    ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {

    @Override
    public void onPageSelected(int position) {
        addBottomDots(position);
    }

    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) {

    }

    @Override
    public void onPageScrollStateChanged(int arg0) {

    }
    };
  1. ViewPagerAdapter class

        class ViewPagerAdapter extends PagerAdapter {
        // Declare Variables
        Context context;
        String[] rank;
        String[] country;
        String[] population;
        LayoutInflater inflater;
    
        public ViewPagerAdapter(Context context, ArrayList<String> list, ArrayList<String> ListTotalReturnPrice, String[] population) {
        this.context = context;
        list = list;
        this.country = country;
        this.population = population;
        this.flag = flag;
        }
    
        @Override
        public int getCount() {
        return list.size();
        }
    
        @Override
        public boolean isViewFromObject(View view, Object object) {
        return view == ((LinearLayout) object);
        }
    
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
    
        // Declare Variables
        TextView txtrank;
        TextView txtcountry;
        TextView txtpopulation;
    
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View itemView = inflater.inflate(R.layout.activity_main_investment_popup, container, false);
    
        // Locate the TextViews in viewpager_item.xml
        txtrank = (TextView) itemView.findViewById(R.id.popUpMenuTitle2);
        txtcountry = (TextView) itemView.findViewById(R.id.textView21);
        txtpopulation = (TextView) itemView.findViewById(R.id.textView25);
    
        // Capture position and set to the TextViews
        txtrank.setText(list.get(position));
        txtcountry.setText(ListTotalReturnPrice.get(position));
        // Add viewpager_item.xml to ViewPager
        ((ViewPager) container).addView(itemView);
    
        return itemView;
    }
    
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // Remove viewpager_item.xml from ViewPager
        ((ViewPager) container).removeView((LinearLayout) object);
    
    }
    }
    
  2. pop up xml

enter image description here

  1. view pager xml enter image description here
Comments