public
class
JOrder
implements
Serializable{
String menu;
int
amount;
int
price;
boolean
choice =
false
;
public
String getMenu() {
return
menu;
}
public
void
setMenu(String menu) {
this
.menu = menu;
}
public
int
getAmount() {
return
amount;
}
public
void
setAmount(
int
amount) {
this
.amount = amount;
}
public
int
getPrice() {
return
price;
}
public
void
setPrice(
int
price) {
this
.price = price;
}
public
boolean
isChoice() {
return
choice;
}
public
void
setChoice(
boolean
choice) {
this
.choice = choice;
}
}
----------------------------------------------------food1_ListAdapter-------------------
public
class
Food1_ListAdapter
extends
BaseAdapter {
Activity context;
ArrayList<JOrder> arrList;
ArrayList<HashMap<JOrder,JOrder>> arrList2;
HashMap<JOrder,JOrder> map;
JOrder jOrder;
int
layout;
public
Food1_ListAdapter(Activity context, ArrayList<JOrder> arrList,
int
layout) {
this
.context = context;
this
.arrList = arrList;
this
.layout = layout;
}
public
int
getCount() {
return
arrList.size();
}
public
Object getItem(
int
position) {
return
arrList.get(position);
}
public
long
getItemId(
int
position) {
return
position;
}
public
View getView(
final
int
position, View convertView, ViewGroup parent) {
View v =
null
;
if
(convertView ==
null
) {
v = context.getLayoutInflater().inflate(layout,
null
);
}
else
{
v = convertView;
}
TextView food1_list_menu = (TextView) v
.findViewById(R.id.food1_list_menu);
final
EditText food1_list_amount = (EditText) v
.findViewById(R.id.food1_list_amount);
TextView food1_list_price = (TextView) v
.findViewById(R.id.food1_list_price);
final
CheckBox food1_list_choice = (CheckBox) v
.findViewById(R.id.food1_list_choice);
jOrder = arrList.get(position);
food1_list_choice
.setOnCheckedChangeListener(
new
OnCheckedChangeListener() {
public
void
onCheckedChanged(CompoundButton buttonView,
boolean
isChecked) {
if
(food1_list_choice.isChecked()) {
jOrder.setChoice(
true
);
map.put(jOrder);
arrList.add(jOrder);
Toast.makeText(context,
"체크되었습니다"
,
Toast.LENGTH_SHORT).show();
}
else
{
jOrder.setChoice(
false
);
map.remove(jOrder.getMenu());
Toast.makeText(context,
"체크가 해제되었습니다."
,
Toast.LENGTH_SHORT).show();
}
}
});
food1_list_amount.addTextChangedListener(
new
TextWatcher() {
public
void
onTextChanged(CharSequence s,
int
start,
int
before,
int
count) {
jOrder.setAmount(Integer.parseInt(food1_list_amount.getText().toString()));
arrList.add(jOrder);
}
public
void
beforeTextChanged(CharSequence s,
int
start,
int
count,
int
after) {
}
public
void
afterTextChanged(Editable s) {
}
});
jOrder = arrList.get(position);
food1_list_menu.setText(jOrder.getMenu());
food1_list_price.setText(
""
+ jOrder.getPrice());
return
v;
}
}
--------------------------------------------------------Food1----------------------------
public
class
Food1
extends
Activity
implements
OnClickListener {
Button order_btn;
ArrayList<JOrder> jOrder_lit;
ListView food1_list;
JOrder jorder =
new
JOrder();
String test =
""
;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.food1);
food1_list = (ListView) findViewById(R.id.food1_list);
onFood1List();
order_btn = (Button) findViewById(R.id.order_food1_btn);
order_btn.setOnClickListener(
this
);
}
public
void
onClick(View v) {
if
(v.getId() == R.id.order_food1_btn) {
Food1_ListAdapter food1 =
new
Food1_ListAdapter(getParent(),
jOrder_lit, R.id.food1_list);
ArrayList<JOrder> jOrder_lit =
new
ArrayList<JOrder>();
JOrder jorder =
new
JOrder();
for
(
int
i =
0
; i < food1.arrList.size(); i++) {
jorder = food1.arrList.get(i);
if
(jorder.isChoice() ==
true
) {
jOrder_lit.add(jorder);
}
}
Intent order_intent =
new
Intent(
this
, Pay.
class
);
order_intent.putExtra(
"order_list"
, jOrder_lit);
startActivity(order_intent);
}
}
private
void
onFood1List() {
ServerRequest request =
new
ServerRequest();
Map<String, String> map =
new
HashMap<String, String>();
request.Order_List(map, handler,
100
);
}
Handler handler =
new
Handler() {
public
void
handleMessage(Message msg) {
super
.handleMessage(msg);
if
(msg.what ==
100
) {
jOrder_lit = (ArrayList<JOrder>) msg.obj;
food1_list.setAdapter(
new
Food1_ListAdapter(Food1.
this
,
jOrder_lit, R.layout.food1_layout));
food1_list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
else
{
Toast.makeText(getApplicationContext(),
"fail"
,
Toast.LENGTH_SHORT).show();
}
}
};
}