Food1_ListAdapter에서 hashamp에 따로 저장시켜놓고, Food1에서 값을 가져오고 싶은데 혹시 방법이있나요...?
Food1_ListAdapter에서는 hashmap에 정상적으로 값이 들어가는데 Food1에서 키 값을 가져오니 계속.... 널이 떨어지네요,.. 혹시 가져 오는 방법이 있다면 좀 가르쳐 주시면 감사하겠습니다.....
Food1으로 키값들을 들고와서 arrList에 담아서 Pay로 보내야하는데
지금 이 문제때문에 몇일동안 내내 수정해보고있는데 진짜로 안되네요......ㅠㅠㅠ 도와주십시요.....
미니님 가르쳐주신대로 해보는데 잘 안되네요..... ㅠ 계속 food1리스트어댑터에 저장시켜놓은 hashmap을 가져올려는데 Food1에서는 널이 뜨니.. ㅠ
public class Food1_ListAdapter extends BaseAdapter {
Activity context;
ArrayList<JOrder> arrList;
HashMap<String,String> map = new HashMap<String, String>();
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(),"2000");
Log.i("test","check:" + map.get(jOrder.getMenu()));
Toast.makeText(context, "체크되었습니다",
Toast.LENGTH_SHORT).show();
} else {
// jOrder.setChoice(false);
map.remove(jOrder.getMenu());
Log.i("test","check.remove:" + map.get(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()){
map.put(jOrder.getMenu(),"3000");
Log.i("test","editText.put:" + map.get(jOrder.getMenu()));
}
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());
Log.i("test","editText.remove:" + map.get(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;
}
}
public class Food1 extends Activity implements OnClickListener {
Button order_btn;
ArrayList<JOrder> jOrder_lit;
HashMap<String, String> map;
ListView food1_list;
@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<HashMap<String, String>> jOrder_lit2;
HashMap<String, String> map = new HashMap<String, String>();
JOrder jOrder;
Log.i("test","map.keyset1()" + food1.map.get(jOrder.getMenu()));
Object jorder = food1.map.keySet().toArray();
for (int cnt = 0; cnt < food1.map.keySet().size(); cnt++) {
jorder = food1.map.get(cnt);
jOrder_lit2.add(jorder);
Log.i("test","map.keyset()2" + map.get(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 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;
}
}
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);
}
}