android wheelview高度,android WheelView组件(滑轮组件)的使用
android前段组件中, 填表单,选择条目 的样式有很多, WheelView滚动组件为其中一种,如下图所示:前两种大家很多都用过, 不过我修改了一下,弄出第三种,希望能帮助到大家:贴代码:EditText category = (EditText) findViewById(R.id.editCategory);category.setOnClickListener(listener);pr.
android前段组件中, 填表单,选择条目 的样式有很多, WheelView滚动组件为其中一种,如下图所示:
前两种大家很多都用过, 不过我修改了一下,弄出第三种,希望能帮助到大家:
贴代码:
EditText category = (EditText) findViewById(R.id.editCategory);
category.setOnClickListener(listener);
private OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
// 创建会话框
final AlertDialog dialog = new AlertDialog.Builder(
Set_accountActivity.this).create();
dialog.setTitle("消费类别:");
// 创建布局
final LinearLayout ll = new LinearLayout(Set_accountActivity.this);
// 设置布局方式:水平
ll.setOrientation(LinearLayout.HORIZONTAL);
final WheelView category1 = new WheelView(Set_accountActivity.this);
category1.setVisibleItems(5);
category1.setCyclic(true);
category1.setAdapter(new ArrayWheelAdapter(category_str1));
final WheelView category2 = new WheelView(Set_accountActivity.this);
category2.setVisibleItems(5);
category2.setCyclic(true);
category2
.setAdapter(new ArrayWheelAdapter(category_str2[0]));
// 创建参数
LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp1.gravity = Gravity.LEFT;
//lp1.weight = (float) 0.6;
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp2.weight = (float) 0.6;
lp2.gravity = Gravity.RIGHT;
lp2.leftMargin = 10;
ll.addView(category1, lp1);
ll.addView(category2, lp2);
// 为category1添加监听
category1.addChangingListener(new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue,
int newValue) {
category2.setAdapter(new ArrayWheelAdapter(
category_str2[newValue]));
category2
.setCurrentItem(category_str2[newValue].length / 2);
}
});
// 为会话创建确定按钮
dialog.setButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String cat1 = category_str1[category1.getCurrentItem()];
String cat2 = category_str2[category1.getCurrentItem()][category2
.getCurrentItem()];
category.setText(cat1 + ">>" + cat2);
dialog.dismiss();
}
});
dialog.setButton2("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.setView(ll);
dialog.show();
}
};
这个组件一般适用于前段选择固有项目 , 核心代码是写好的,大家去搜索一下把源码下载下来就可以了;
更多推荐
所有评论(0)