I just need to have a price next to my products in a listView and they need to be aligned as follows,
- The product name to the left, and;
- The price to the right
This is the code:
public ListView lstMenuItems;
public String[] menuItems = {"Fillet On The Bone", "Rump", "Sirloin", "French Cut Pork Cutlets", "Spatchcock Chicken", "Sticky Smoked Paprika Chicken Wings", "Craft Beer Battered Fish", "Butter Chicken", "Pomegranate & Chilli Marinated Lamb Skewer", "Pork Belly Skewer", "Harissa Basted Chicken Skewer"};
public double[] itemPrice = {135, 99, 99, 99, 89, 79, 60, 75, 99, 95, 69};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
TitleBar(waiterName);
GetListViewValue();
menuItems = AddPad(menuItems, itemPrice);
MenuList();
}
public void MenuList() {
lstMenuItems = (ListView)findViewById(R.id.lvProducts);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.category_list, menuItems);
lstMenuItems.setAdapter(adapter);
}
public String[] AddPad(String[] menu, double[] price) {
NumberFormat format = NumberFormat.getCurrencyInstance(Locale.getDefault());
for (int i = 0; i < menu.length; i++) {
menu[i] = String.format("%-60s %s",menu[i], format.format(price[i]));
}
return menu;
}
The String.format
class doesn't seem to be working. Is there a way to do this?
Please Help