我有動態列表視圖活動,它將項目轉移到另一個具有編輯文本(名稱,電話,表格)和另一個動態列表視圖的活動。在Android動態列表視圖發送前添加數據
每個項目都有它應該與每個項目發送的編輯文本。
public class OrderAdapter extends BaseAdapter {
private Context ctx;
private LayoutInflater mInflater;
private List<Item> orderItems;
private DatabaseHelper helper;
public OrderAdapter(Context context, List<Item> items) {
// TODO Auto-generated constructor stub
ctx = context;
helper = new DatabaseHelper(ctx);
mInflater = LayoutInflater.from(ctx);
orderItems = items;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return orderItems.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return orderItems.get(position).getItemID();
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public class ViewHolder {
TextView name, desc, price, total;
EditText etQty;
Button btnDelete, btnAdd, btnMinus;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.order_preview_row, parent,
false);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.c_table);
holder.desc = (TextView) convertView.findViewById(R.id.order_item_name);
holder.price = (TextView) convertView.findViewById(R.id.tvOpPrice);
holder.etQty = (EditText) convertView.findViewById(R.id.etQty);
holder.btnAdd = (Button) convertView
.findViewById(R.id.btnIncreaseQty);
holder.btnAdd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
float total_qty = (Float.parseFloat(holder.etQty.getText()
.toString()) + 1);
Item item = (Item) holder.etQty.getTag();
item.setNoItems(String.valueOf(total_qty));
holder.etQty.setText(String.valueOf(total_qty));
holder.total.setText(" = "
+ (Float.parseFloat(orderItems.get(position)
.getItemPrice()) * Float
.parseFloat(holder.etQty.getText().toString())));
}
});
holder.btnMinus = (Button) convertView
.findViewById(R.id.btnDecreaseQty);
holder.btnMinus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Float total_qty = (Float.parseFloat(holder.etQty.getText()
.toString()) - 1);
if (total_qty != 0) {
Item item = (Item) holder.etQty.getTag();
item.setNoItems(String.valueOf(total_qty));
holder.etQty.setText(String.valueOf(total_qty));
holder.total.setText(" = "
+ (Float.parseFloat(orderItems.get(position)
.getItemPrice()) * Float
.parseFloat(holder.etQty.getText()
.toString())));
}
}
});
holder.btnDelete = (Button) convertView
.findViewById(R.id.btnDeleteItem);
holder.btnDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
helper.deleteItem(orderItems.get(position).getItemID());
orderItems.remove(position);
notifyDataSetChanged();
}
});
holder.total = (TextView) convertView.findViewById(R.id.tvTotal);
holder.etQty.setTag(orderItems.get(position));
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
holder.etQty.setTag(orderItems.get(position));
}
holder.name.setText(orderItems.get(position).getItemName());
holder.desc.setText(orderItems.get(position).getItemDescription());
holder.price.setText(orderItems.get(position).getItemPrice() + " x ");
holder.etQty.setText(orderItems.get(position).getNItems());
holder.total
.setText(" = "
+ (Float.parseFloat(orderItems.get(position)
.getItemPrice()) * Float
.parseFloat(holder.etQty.getText().toString())));
return convertView;
}
}
我的問題是如何調用從編輯的文本數據與例如項目名稱是每個項目
添加:「奶酪比薩餅」我希望它「2奶酪比薩餅」
@Override
protected Boolean doInBackground(Void... params) {
// TODO Auto-generated method stub
item_ids = new StringBuilder();
for (int i = 0; i < orderItems.size(); i++) {
item_ids.append(orderItems.get(i).getItemID()).append(",");
}
if (item_ids.length() == 0)
return false;
else
item_ids.deleteCharAt(item_ids.length() - 1);
Log.d("OrderPreview", item_ids.toString());
item_names = new StringBuilder();
for (int i = 0; i < orderItems.size(); i++) {
item_names.append(orderItems.get(i).getItemName()).append(",");
}
if (item_names.length() == 0)
return false;
else
item_names.deleteCharAt(item_names.length() - 1);
Log.d("OrderPreview", item_names.toString());
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(Utils.WS_ADD_ORDER);
List<NameValuePair> mParams = new ArrayList<NameValuePair>();
mParams.add(new BasicNameValuePair("name", etName.getText()
.toString()));
mParams.add(new BasicNameValuePair("phone", etPhone.getText()
.toString()));
mParams.add(new BasicNameValuePair("table", etTable.getText()
.toString()));
mParams.add(new BasicNameValuePair("order_status", "Processing"));
mParams.add(new BasicNameValuePair("id", item_ids.toString()));
mParams.add(new BasicNameValuePair("items", item_names.toString()));
究竟是什麼問題? –
我想從etQty編輯文本調用變量來打印它與item_name –