서버에서 받아온 DB값을 Food1_ListAdapter에 세팅한 뒤 수량을 입력하고, 체크박스 체크를 하면, 체크 된 값들만 저장하여 Pay.java에 있는 리스트어댑터로 값을 전달 해주고 싶습니다.
Food1에서 Food1_ListAdapter에 체크 된 값들을 어떤식으로 가져 올수가 있나요? 가져와서 주문하기 버튼을 눌릴 때 안에다가 if문 비교해서 값을 넘기면 될거같긴한데... 잘안되네요 ㅠ
---------------------------------------ListAdapter.java-----------------------------------
public class Food1_ListAdapter extends BaseAdapter {
Activity context;
ArrayList<JOrder> arrList;
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);
TextView food1_list_price = (TextView)v.findViewById(R.id.food1_list_price);
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) {
JOrder jOrder;
jOrder = arrList.get(position);
if(isChecked){
jOrder.setChoice(true);
Toast.makeText(context, "체크되었습니다", Toast.LENGTH_SHORT).show();
}else{
jOrder.setChoice(false);
Toast.makeText(context, "체크가 해제되었습니다.", Toast.LENGTH_SHORT).show();
}
}
});
JOrder jOrder;
jOrder = arrList.get(position);
food1_list_menu.setText(jOrder.getMenu());
// jOrder.setAmount(food1_list_amount.getText().toString());
food1_list_price.setText(""+jOrder.getPrice());
return v;
}
}
----------------------------------------------Food1.java----------------------------------
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) {
if(food1_list.getAdapter().getItem(position)){
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();
}
}
};
}
----------------------------------------JOrder.java---------------------------------------
public class JOrder implements Serializable{
String menu;
int price;
String amount;
boolean choice = false;
public String getMenu() {
return menu;
}
public void setMenu(String menu) {
this.menu = menu;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public boolean isChoice() {
return choice;
}
public void setChoice(boolean choice) {
this.choice = choice;
}
}