public class Food1_ListAdapter extends BaseAdapter {
Activity context;
ArrayList<JOrder> arrList;
HashMap<String,Integer> map = new HashMap<String,Integer >();
JOrder jOrder = new 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;
}
final 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);
final 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);
food1_list_choice
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (food1_list_choice.isChecked()) {
map.put(arrList.get(position).getMenu(),arrList.get(position).getPrice());
Log.i("test","check:" + map.get(arrList.get(position).getMenu()));
Toast.makeText(context, "체크되었습니다",
Toast.LENGTH_SHORT).show();
} else {
map.remove(arrList.get(position).getMenu());
Log.i("test","check.remove:" + map.get(arrList.get(position).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) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
// if(food1_list_choice.isChecked()){
//
// map.put(arrList.get(position).getMenu(),arrList.get(position).getPrice());
// Log.i("test","editText.put:" + map.get(arrList.get(position).getMenu()));
//
// }
// else if(Integer.parseInt(food1_list_amount.getText().toString()) == 0 || food1_list_amount.getText().toString() == null || food1_list_choice.isChecked() == false){
// map.remove(arrList.get(position).getMenu());
//
// Log.i("test","editText.remove:" + map.get(arrList.get(position).getMenu()));
//
// }
}
});
jOrder = arrList.get(position);
food1_list_menu.setText(jOrder.getMenu());
// food1_list_amount.setText("");
food1_list_price.setText("" + jOrder.getPrice());
return v;
}
public HashMap<String, Integer> getData(){
return map;
}
}
public class Food1 extends Activity implements OnClickListener {
Button order_btn;
ArrayList<JOrder> jOrder_lit;
ArrayList<JOrder> jOrder_lit2;
ListView food1_list;
JOrder jOrder;
@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 = (Food1_ListAdapter) food1_list.getAdapter();
Log.i("test", "getkey:" + food1.getData().keySet().size());
for (int cnt = 0; cnt < food1.map.keySet().size(); cnt++) {
Object keys = food1.map.get(food1.arrList.get(cnt).getMenu());
jOrder_lit2.add((JOrder)keys);
}
Intent order_intent = new Intent();
Bundle bundle = new Bundle();
bundle.putSerializable("order_list", jOrder_lit2);
order_intent.putExtras(bundle);
// 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 = this.getIntent();
Bundle bundle = intent.getExtras();
ArrayList<JOrder> jOrder_List= (ArrayList<JOrder>)bundle.getSerializable("order_list");
// 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);
}
}
요 몇일 hashmap문제로 잘안되다가 처음부터 다시 차근차근찍어가면서 해보자는식으로 하여
food1_ListAdapter에 정상적으로 hashamp 키값 정상적으로 체크할시에 들어가는거 확인하였구
food1클래스에서 받는거도 확인을 하였습니다.
이제 밑에 이부분을 food1의 jOrder_lit2에 담아서 Pay클래스로 보낼려는데 자꾸 앱이죽습니다.
로그는 찍어봤는데 값은 정상적으로 찍히구요....
혹시 다른형태로 바꿔준뒤에 arrayList에다가 담아야 하는건가요?? ㅠㅠ 힌트나 원인 좀 알려주시면 감사하겠습니다.
food1.map.get(food1.arrList.get(cnt).getMenu())