@Meh для u ..
txtlist.setFilters(new InputFilter[] { new DigitsKeyListener( Boolean.FALSE,Boolean.TRUE) {
int beforeDecimal = 7;
int afterDecimal = 2;
@Override
public CharSequence filter(CharSequence source, int start, int end,Spanned dest, int dstart, int dend) {
String etText = txtlist.getText().toString();
String temp = txtlist.getText() + source.toString();
if (temp.equals(".")) {
return "0.";
} else if (temp.toString().indexOf(".") == -1) {
// no decimal point placed yet
if (temp.length() > beforeDecimal) {
return "";
}
} else {
int dotPosition ;
int cursorPositon = txtlistprice.getSelectionStart();
if (etText.indexOf(".") == -1) {
dotPosition = temp.indexOf(".");
}else{
dotPosition = etText.indexOf(".");
}
if(cursorPositon <= dotPosition){
String beforeDot = etText.substring(0, dotPosition);
if(beforeDot.length()<beforeDecimal){
return source;
}else{
if(source.toString().equalsIgnoreCase(".")){
return source;
}else{
return "";
}
}
}else{
temp = temp.substring(temp.indexOf(".") + 1);
if (temp.length() > afterDecimal) {
return "";
}
}
}
return super.filter(source, start, end, dest, dstart, dend);
}
} });
Просто установите "Value"
и "Key"
для dataValueField
и dataTextField
. Вы можете сделать это либо в самом View, либо в своих действиях (код ниже не тестировался).
var targets = new Dictionary<string, string>(); targets.Add("Key", "Value"); ViewData["MyList"] = new SelectList(targets, "Key", "Value");
Ну, IDictionary
наследуется от IEnumerable
, поэтому вы должны иметь возможность передать этот словарь в один из конструкторов для SelectList
.