我正在使用欧芹,这太棒了!我想在data-parsley-pattern中定义不同的模式,以限制字段中的10个数字输入。
例如01234567897。
答案 0 :(得分:1)
我解决了:
public class new_frame extends AppCompatActivity {
public int toState = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_frame);
Display display = getWindowManager().getDefaultDisplay();
final ToggleButton toStateBTN = (ToggleButton) findViewById(R.id.toggleButton);
toStateBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(toState == 1){
toState = 0;
}else if(toState == 0){
toState = 1;
}else{
Toast.makeText(getApplicationContext(),"Something went wrong",Toast.LENGTH_SHORT).show();
}
}
});
Point size = new Point();
display.getSize(size);
int width = size.x;
int Dim = width / 24;
RelativeLayout View = (RelativeLayout) findViewById(R.id.Layout);
for (int i = 0;i<View.getChildCount();i++) {
View v = View.getChildAt(i);
if (v instanceof ImageView) {
//((ImageView) v).setMaxHeight(ledDim);
//((ImageView) v).setMaxWidth(ledDim);
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams)v.getLayoutParams();
Log.d("NewFrame", "child found: " + v.getId() + ". Set dimensions from " + params.height + "," + params.width + " to " + Dim + "," + Dim);
params.width = Dim;
params.height = Dim;
v.setLayoutParams(params);
v.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
ImageView view = (ImageView) v;
if(toState == 1){
view.setImageResource(R.mipmap.dot_on);
}else if(toState == 0){
view.setImageResource(R.mipmap.dot_off);
}
return false;
}
});
}
}
}
}
答案 1 :(得分:0)
您可以尝试以下方式:
pattern="^[0-9]{1,10}$"