Wheel picker on dialog box android

后端 未结 1 1156
南旧
南旧 2021-01-14 11:20

I want to get text from spin wheel as password. Can you please give me any example of spin wheel for getting text from it. I didn\'t get any good example. Thanks in advance.

1条回答
  •  执笔经年
    2021-01-14 11:32

    enter image description here

    I was trying to get this spin wheel at last I have build my wheel for getting the texts from the users. I am giving a example for four integers.

     package com.example.wheel;
    
     import kankan.wheel.widget.ArrayWheelAdapter;
     import kankan.wheel.widget.OnWheelChangedListener;
     import kankan.wheel.widget.OnWheelScrollListener;
     import kankan.wheel.widget.WheelView;
     import android.R.color;
     import android.app.Activity;
     import android.app.Dialog;
     import android.os.Bundle;
     import android.view.View;
     import android.view.Window;
     import android.widget.Button;
    
    public class Wheelboxtcr extends Dialog implements
        android.view.View.OnClickListener {
    
    String wheelMenu1[] = new String[] { "0", "1", "2", "3", "4", "5", "6",
            "7", "8", "9" };
    /*String wheelMenu2[] = new String[] { "A", "B", "C", "D", "E", "F", "G",
            "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z" };*/
    
    boolean wheelScrolled = false;
    public Activity c;
    public Dialog d;
    public Button button;
    
    public Wheelboxtcr(Activity a) {
        super(a);
        // TODO Auto-generated constructor stub
        this.c = a;
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(color.transparent);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.wheellayouttcr);
        button = (Button) findViewById(R.id.btn);
        button.setOnClickListener(this);
        initWheel1(R.id.p1);
        initWheel2(R.id.p2);
        initWheel3(R.id.p3);
        initWheel4(R.id.p4);
    
    }
    
    OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {
        public void onScrollStarts(WheelView wheel) {
            wheelScrolled = true;
        }
    
        public void onScrollEnds(WheelView wheel) {
            wheelScrolled = false;
            updateStatus();
        }
    };
    
    // Wheel changed listener
    private final OnWheelChangedListener changedListener = new OnWheelChangedListener() {
        public void onChanged(WheelView wheel, int oldValue, int newValue) {
            if (!wheelScrolled) {
                updateStatus();
            }
        }
    };
    
    /**
     * Updates entered PIN status
     */
    private void updateStatus() {
        // Main.text3.setText(wheelMenu2[getWheel(R.id.p3).getCurrentItem()]);
    
    }
    
    private void initWheel1(int id) {
        WheelView wheel = (WheelView) findViewById(id);
    
        wheel.setAdapter(new ArrayWheelAdapter(wheelMenu1));
        wheel.setVisibleItems(2);
        wheel.setCurrentItem(0);
        wheel.addChangingListener(changedListener);
        wheel.addScrollingListener(scrolledListener);
    }
    
    private void initWheel2(int id) {
        WheelView wheel = (WheelView) findViewById(id);
    
        wheel.setAdapter(new ArrayWheelAdapter(wheelMenu1));
        wheel.setVisibleItems(2);
        wheel.setCurrentItem(0);
        wheel.addChangingListener(changedListener);
        wheel.addScrollingListener(scrolledListener);
    }
    
    private void initWheel3(int id) {
        WheelView wheel = (WheelView) findViewById(id);
    
        wheel.setAdapter(new ArrayWheelAdapter(wheelMenu1));
        wheel.setVisibleItems(2);
        wheel.setCurrentItem(0);
        wheel.addChangingListener(changedListener);
        wheel.addScrollingListener(scrolledListener);
    }
    
    private void initWheel4(int id) {
        WheelView wheel = (WheelView) findViewById(id);
    
        wheel.setAdapter(new ArrayWheelAdapter(wheelMenu1));
        wheel.setVisibleItems(2);
        wheel.setCurrentItem(0);
        wheel.addChangingListener(changedListener);
        wheel.addScrollingListener(scrolledListener);
    }
    
    
    private WheelView getWheel(int id) {
        return (WheelView) findViewById(id);
    }
    
    private int getWheelValue(int id) {
        return getWheel(id).getCurrentItem();
    }
    
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btn: {
            String s = wheelMenu1[getWheel(R.id.p1).getCurrentItem()]
                    + wheelMenu1[getWheel(R.id.p2).getCurrentItem()]
                    + wheelMenu1[getWheel(R.id.p3).getCurrentItem()]
                    + wheelMenu1[getWheel(R.id.p4).getCurrentItem()]
                    ;
    
            Display.jno.setText(s);
            break;
        }
    
        default:
            break;
        }
        dismiss();
    }
    }
    

    It's layout

    
     
    
    
    
        
    
        
    
        
    
        
    
        

    0 讨论(0)
提交回复
热议问题