在我的应用程序中,当我选择要订购的项目时,所选项目将在“有序”页面中列入候选名单。当我单击“订购”按钮时,所选项目将存储在数据库中。这里的问题是当我选择一个项目并且我再次订购时如果我选择要订购的项目,之前订购的商品也会在订购页面中进入候选名单。 请帮我解决这个问题。
public class SelectedItem extends Activity {
private ListView lv;
private CustomAdapter adapter;
int tableid;
String id;
ArrayList<String> arr = new ArrayList<String>();
ArrayList<String> price = new ArrayList<String>();
ArrayList<Bitmap> image = new ArrayList<Bitmap>();
Double amountvalue;
TextView totalamount;
Button order;
String dtotalamount;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
arr = getIntent().getStringArrayListExtra("itemname");
price = getIntent().getStringArrayListExtra("itemprice");
image = getIntent().getExtras().getParcelableArrayList("itemimage");
setContentView(R.layout.selecteditem);
lv = (ListView) findViewById(R.id.selecteditemlist);
adapter = new CustomAdapter(this, arr, price, image);
lv.setAdapter(adapter);
amountvalue = CustomAdapter.x;
System.out.println(amountvalue);
totalamount = (TextView) findViewById(R.id.amount);
totalamount.setText(String.valueOf(amountvalue));
order = (Button) findViewById(R.id.order);
order.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
tableid = Login.tableid;
id = Integer.toString(tableid);
System.out.println(id);
String x = amountvalue.toString();
System.out.println(x);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs
.add(new BasicNameValuePair("tableid", id));
nameValuePairs.add(new BasicNameValuePair(
"totalamount", amountvalue.toString()));
nameValuePairs.add(new BasicNameValuePair("itemnames",
arr.toString()));
nameValuePairs.add(new BasicNameValuePair("price",
price.toString()));
System.out.println(arr.toString());
System.out.println(price.toString());
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://...........");
httppost.setEntity(new UrlEncodedFormEntity(
nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
Toast.makeText(getApplicationContext(),
"Saved Sucessfully", Toast.LENGTH_SHORT).show();
String responseBody = EntityUtils.toString(response
.getEntity());
System.out.println("Responce is :: " + responseBody);
lv.clearTextFilter();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(),
"Network Error", 3000).show();
}
}
});
}
}