我已經看過大部分討論這個問題的問題,但似乎找不到解決我的問題的任何問題。我有一個自定義數組適配器將數據傳遞給一個列表,我需要列表刷新一次,我已經刪除了一個項目,我明白,notifyDataSetChanged()應該是我的解決方案,但還沒有使它工作 對不起,我亂的代碼 但我仍然在學習:) 任何幫助,將不勝感激,感謝名單:)自定義陣列適配器內的刷新列表
我的適配器:
public class CustomBasketAdapter extends ArrayAdapter<String>
{
private String TAG ="Vik";
public String stringEmail= "";
public String stringStore= "";
private String product = "";
private String quantity = "";
private String store = "";
//String[] stringEmail={"[email protected]"};
private final Activity context;
private final String[] storename;
private final String[] itemprice;
private final String[] itemname;
private final String[] productquantity;
private final String[] basketlinetotal;
//public CustomListAdapter(Activity context, String[] itemname,String[] itemprice, Integer[] imgid) {
public CustomBasketAdapter(Activity context, String[] storename,String[] itemprice, String[] productquantity, String[] itemname, String[] basketlinetotal) {
super(context, R.layout.viewbasket_layout, storename);
// TODO Auto-generated constructor stub
this.context=context;
this.storename=storename;
this.itemprice=itemprice;
this.itemname=itemname;
this.productquantity=productquantity;
this.basketlinetotal=basketlinetotal;
Intent intent = ((Activity) context).getIntent();
if (null != intent)
{
stringEmail = intent.getStringExtra("EmailAddress");
stringStore = intent.getStringExtra("StoreDescription");
}
Toast toast = Toast.makeText(getContext(),stringEmail, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 10);
//toast.show();
}
public View getView(int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.viewbasket_layout, null,true);
final TextView txtstore = (TextView) rowView.findViewById(R.id.txtstorename);
final TextView txtproduct = (TextView) rowView.findViewById(R.id.txtproduct);
final TextView txtquantity = (TextView) rowView.findViewById(R.id.txtquantity);
TextView txtprice = (TextView) rowView.findViewById(R.id.txtprice);
TextView txttotal = (TextView) rowView.findViewById(R.id.txttotal);
Button btnclear = (Button) rowView.findViewById(R.id.btnclearitem);
txtstore.setText(storename[position]);
txtproduct.setText(itemname[position]);
txtquantity.setText(productquantity[position]);
txtprice.setText(itemprice[position]);
txttotal.setText(basketlinetotal[position]);
btnclear.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
product = txtproduct.getText().toString();
quantity = txtquantity.getText().toString();
store = txtstore.getText().toString();
DeleteFromBasket();
Toast toast = Toast.makeText(getContext(),"Item Cleared", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 10);
toast.show();
notifyDataSetChanged();
}
/*your onclick code*/
});
return rowView;
};
public void ChannelToService()
{
String SOAP_ACTION = "http://tempuri.org/ITHubServ/DeleteFromBasket";
String METHOD_NAME = "DeleteFromBasket";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://www.buh34nart.co.za/THubServ.svc?wsdl";
String OrderLine = "";
try{
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
String basketline = stringEmail + "|" + store + "|" + product.replace("|", "") + "|" + quantity;
//OrderLine = OrderLine.substring(0,OrderLine.length() -1);
Request.addProperty("Line", basketline);
//Request.addProperty("UserPassword", txtPass.getText().toString());
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE transport= new HttpTransportSE(URL);
Object Response = null;
transport.call(SOAP_ACTION, soapEnvelope);
Response = soapEnvelope.getResponse();
// data = Response.toString().split("[\\x7C]");
//Log.i(TAG, "Result Order: " + Response);
//if(Response.toString().equals("1"))
//{
// runOnUiThread(new Runnable() {
// public void run() {
//Toast toast = Toast.makeText(LoginPage.this,"Incorrect Username/Password" +
//" Login Failed", Toast.LENGTH_LONG);
//toast.setGravity(Gravity.CENTER, 0, 10);
//toast.show();
//Not Registered or psw wrong or email wrong (forgot password)
// }
// });
//}
//else
//{
// if(Response.toString().equals("9"))
// {
// startActivity(new Intent("com.ctc.android.widget.TechnicalError"));
// // Probleem met system Technical
// }
// else
// {
//btnloginclick();
// }
// }
}
catch(Exception Ex) {}
}
public void DeleteFromBasket()
{
AsyncCallWS task = new AsyncCallWS();
task.execute();
}
private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
ProgressDialog progDailog = new ProgressDialog(getContext());
@Override
protected Void doInBackground(Void... params) {
Log.i(TAG, "doInBackground");
ChannelToService();
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
CustomBasketAdapter.this.clear();
CustomBasketAdapter.this.addAll();
CustomBasketAdapter.this.notifyDataSetChanged();
progDailog.dismiss();
}
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
super.onPreExecute();
progDailog.setMessage("Loading...");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(true);
progDailog.show();
}
@Override
protected void onProgressUpdate(Void... values) {
Log.i(TAG, "onProgressUpdate");
}
}
}
我改變了代碼保護無效onPostExecute(Void結果){ Log.i(TAG,「onPostExecute」); CustomBasketAdapter.this.remove(product); CustomBasketAdapter.this.notifyDataSetChanged(); progDailog.dismiss();但它不刷新列表 – 2015-02-06 10:11:18