Formatting numbers in a ListView!

Интерфейс, диалоги, темы, стили, меню
Ответить
EleanorGrace
Сообщения: 11
Зарегистрирован: 05 май 2021, 08:05

Formatting numbers in a ListView!

Сообщение EleanorGrace » 10 май 2021, 12:44

I have a list with numbers. I wanted to format the output of numbers in the format ####. 00
found a simple solution
THE CODE: SELECT ALL

public class Sprav_Tariff_Browse extends Activity
{

DecimalFormat myCustDecFormatter = new DecimalFormat("######.00");
...

/*-----------------------------------------------------------------------*/
/* получаем данные в курсор */
/*-----------------------------------------------------------------------*/
@SuppressWarnings("deprecation")
public void refreshCursor()
{
cursor = db.getAllData_Tariff();
//startManagingCursor(cursor);

String f[] = new String[] {kCalcDB.TBL_CATEGORY_NAMECAT, kCalcDB.TBL_TARIFF_TARIFF};
int t[] = new int[] {R.id.textView_Sprav_Tariff_CategoryName_Item, R.id.textView_infoStr};

scAdapter = new SimpleCursorAdapter(this, R.layout.sprav_tariff_item, cursor, f, t)
{
@Override
public void setViewText(TextView v, String text)
{
super.setViewText(v, fmt(v, text));
}
};

lw = (ListView) findViewById(R.id.SpravTariffLW);
lw.setAdapter(scAdapter); 192.168.0.1 routerlogin 192.168.l.l

}

/*-----------------------------------------------------------------------*/
/* форматируем число(тариф) в адаптере */
/*-----------------------------------------------------------------------*/
private String fmt(View v, String text)
{
if (v.getId()==R.id.textView_infoStr)
{
Double d = cursor.getDouble(cursor.getColumnIndex(kCalcDB.TBL_TARIFF_TARIFF));
return myCustDecFormatter.format(d);
}
return text;
}

then we define the format myCustDecFormatter , we override the setView method in the adapter constructor. Easy, simple, gracefully
taken from herehttp://androidforums.com/application-de ... tview.html

Ответить