在我的应用程序中,每当我触摸列表视图项目布局时,我想删除自定义列表项中的行。我尝试在位置的帮助下删除。但它已经停止了。
代码:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Typeface custom_regular = Typeface.createFromAsset(activity.getAssets(),
"fonts/OpenSans-Regular.ttf");
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.recharge_listitem, null);
TextView orderitemid_delete=(TextView)convertView.findViewById(R.id.orderitemid);
TextView accountnumber = (TextView) convertView
.findViewById(R.id.accountnumber);
TextView servicename = (TextView) convertView
.findViewById(R.id.servicetypname);
TextView planamount = (TextView) convertView
.findViewById(R.id.rechargeamount);
final ImageView close = (ImageView) convertView
.findViewById(R.id.crosse_close_img);
accountnumber.setTypeface(custom_regular);
servicename.setTypeface(custom_regular);
planamount.setTypeface(custom_regular);
//orderitemid = bpData.get(position).getOrderitemID();
// Log.v("TAG_orderitemid",""+orderitemid);
orderid = bpData.get(position).getOrderid();
final LinearLayout layoutrecharge = (LinearLayout) convertView.findViewById(R.id.rechargelay);
layoutrecharge.setTag(position);
accountnumber.setText(bpData.get(position).getAccountNumber());
servicename.setText(bpData.get(position).getServicename());
planamount.setText("Rs." + bpData.get(position).getRechargeamount());
orderitemid_delete.setText(bpData.get(position).getOrderitemID());
totalamount.setText("Rs " + bpData.get(position).getAmount());
layoutrecharge.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new GetdeleteOrderItem().execute(WebUrl.RechargeServiceURL + "deleteOrderItem");
//int deletePos = Integer.parseInt(v.getTag().toString());
TextView orderitemid_delete = (TextView)layoutrecharge
.findViewById(R.id.orderitemid);
orderitemidfordelete = orderitemid_delete.getText().toString();
int deletePos = Integer.parseInt(v.getTag().toString());
bpData.remove(deletePos);
Helper.getListViewSize(recharge_lv);//run it
notifyDataSetChanged();
reloadcas_cb.setChecked(false);
}
});
return convertView;
}
error:
02-26 18:06:55.933 29715-29715/com.reloadapp.reload E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: Invalid index 7, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.remove(ArrayList.java:399)
at com.reloadapp.reload.fragments.Payment_Actiivity$PaymentAdapter$1.onClick(Payment_Actiivity.java:488)
at android.view.View.performClick(View.java:3571)
at android.view.View$PerformClick.run(View.java:14247)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
在我的应用程序中,每当我触摸列表视图项目布局时,我想删除自定义列表项中的行。我尝试在位置的帮助下删除。但它已经停止了。
答案 0 :(得分:0)
请先将您的操作放在asyncTask onPostExecute中并尝试执行以下操作:
yourAdaptersList.remove(positionToRemove);
yourAdapter = new Adapter(yourAdaptersList);
yourListView.setAdapter(yourAdapter);