в моем приложении я отображаю числовые строки и заметил, что «7.000444» отображается как «7.00044». Кроме того, «0,567567» отображается как «0,56757». Наконец, добавление любой нецифровой части (то есть буквы) заставляет их отображаться с полным номером, за которым следует другая клавиша. Есть ли способ остановить поведение первых двух? Я показываю их, добавляя это в базу данных, которая затем отображается в ListView. Код для создания строки представляет собой набор кнопок, для кнопок 0-9 это:
Button one;
one = (Button)findViewById(R.id.one);
one.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
working = BigDecimal.valueOf(1);
now = working.toString();
total1 = total.concat(now);
equation1 = equation.concat(now);
equation = equation1;
total = total1;
if(b){mnDbHelper.updateNote(equation, mnDbHelper.testCount());}
else{mnDbHelper.createNote(equation);
b=true;}
fillData();
}
});
При необходимости 1 изменяется.
Кнопка десятичной точки имеет следующий вид:
Button decimal;
decimal = (Button)findViewById(R.id.decimal);
decimal.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
now = ".";
equation1 = equation.concat(now);
total1 = total.concat(now);
equation = equation1;
total = total1;
if(b){mnDbHelper.updateNote(equation, mnDbHelper.testCount());}
else{mnDbHelper.createNote(equation);
b=true;}
fillData();
}
});
Вот код для FillData:
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = mnDbHelper.fetchAllNotes();
startManagingCursor(c);
String[] columns = new String[] {EquationsDbAdapter.KEY_VALUE};
int to[] = new int[] {android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1 ,c , columns , to);
setListAdapter(adapter);
}
Вот пример кода для одной из других кнопок:
Button times;
times = (Button)findViewById(R.id.times);
times.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
now = "*";
equation1 = equation.concat(now);r = equation;
equation = equation1;z = equation;
if(total!="")
{try{
formatter.parse(total);
}
catch(Throwable t){
really = false;
}
if(really){
try {
mDbHelper.createNote((BigDecimal) formatter.parse(total), fa, fa, fa, fa, fa, fa, jkl, fa, fa);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
total = "";
total1 = "";}
else{really = true;}}
mDbHelper.createNote(jkl, fa, fa, t, fa, fa, fa, jkl, fa, fa);
if(b){mnDbHelper.updateNote(equation, mnDbHelper.testCount());}
else{mnDbHelper.createNote(equation);
b=true;}
fillData();
}
});
Форматер
выглядит следующим образом:
DecimalFormat formatter = new DecimalFormat("##################################################################################.################################");
Редактировать: как ни странно, отображаемое «0.33333333» не отображается правильно, но при добавлении * оно отображается, однако, когда * вычитается из него снова, оно не отображается
Как всегда, помощь очень ценится.