참고하여 소스 수정해보았는데...잘안되네요.... 머리 쥐어뜯구 잇네요 ㅠㅠ
Food1_List_Adapter에서 hashmap에 체크 할때와 수량 입력할 때 저장하게끔 해놓고,
food1에서 불러와서 key값 돌리면서 arrayList에 저장하여 인텐트로 Pay로 보내는데
거의 된거 같은데... Pay에 아무런 값이 안나오네요.... 머가 문제인지 좀 알려주시면 감사하겠습니다...
미니님 죄송해요... 다 가르쳐주셨는데.. 제가 제대로 해결을 못하네요 ㅠ
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;
HashMap<String,JOrder> map = new HashMap<String, JOrder>();
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() {
// TODO Auto-generated method stub
return arrList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return arrList.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
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()) {
map.put(jOrder.getMenu(), 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) {
if(food1_list_choice.isChecked()){
// jOrder.setAmount(Integer.parseInt(food1_list_amount.getText().toString()));
map.put(jOrder.getMenu(),jOrder);
// Object jorder = map.keySet().toArray();
// arrList.add(jOrder);
}
else if(Integer.parseInt(food1_list_amount.getText().toString()) == 0 || food1_list_amount.getText().toString() == null || food1_list_choice.isChecked() == false){
map.remove(jOrder.getMenu());
}
}
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_amount.setText("");
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_lit2 = new ArrayList<JOrder>();
HashMap<String, JOrder> map = new HashMap<String, JOrder>();
JOrder jOrder;
Object jorder = map.keySet().toArray();
for (int cnt = 0; cnt < food1.map.keySet().size(); cnt++) {
jorder = food1.map.get(cnt);
jOrder_lit2.add((JOrder)jorder);
}
Intent order_intent = new Intent(this, Pay.class);
order_intent.putExtra("order_list", jOrder_lit2);
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();
}
}
};
}
public class Pay extends Activity implements OnClickListener{
Button pay_btn;
ListView pay_list;
ArrayList<JOrder> jOrder_List;
String tag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pay);
pay_list = (ListView) findViewById(R.id.pay_list);
onPayList();
pay_btn = (Button)findViewById(R.id.pay_btn_go);
pay_btn.setOnClickListener(this);
}
private void onPayList() {
Intent intent = getIntent();
jOrder_List =(ArrayList<JOrder>) intent.getSerializableExtra("order_list");
pay_list.setAdapter(new Pay_ListAdapter(Pay.this,
jOrder_List, R.layout.pay_layout));
}
public void onClick(View v) {
Intent pay_intent = new Intent(this, Pay_result.class);
startActivity(pay_intent);
}
}