Wheel picker on dialog box android(对话框android上的轮子选择器)
本文介绍了对话框android上的轮子选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从旋转轮获取文本作为密码.你能给我任何旋转轮的例子来从中获取文本吗?我没有得到任何好的例子.提前致谢.
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.
推荐答案
我试图得到这个旋转轮,最后我已经建立了我的轮子来从用户那里获取文本.我举了四个整数的例子.
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<String>(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<String>(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<String>(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<String>(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();
}
}
这是布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="103dp"
android:background="@android:color/background_dark"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@android:color/transparent" >
<kankan.wheel.widget.WheelView
android:id="@+id/p1"
android:layout_width="33dp"
android:layout_height="wrap_content" />
<kankan.wheel.widget.WheelView
android:id="@+id/p2"
android:layout_width="33dp"
android:layout_height="wrap_content" />
<kankan.wheel.widget.WheelView
android:id="@+id/p3"
android:layout_width="33dp"
android:layout_height="wrap_content" />
<kankan.wheel.widget.WheelView
android:id="@+id/p4"
android:layout_width="33dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="38dp"
android:clickable="true"
android:gravity="center"
android:text="Set"
android:textColor="#eaa932"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
这篇关于对话框android上的轮子选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:对话框android上的轮子选择器
基础教程推荐
猜你喜欢
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01