我創建其中包括列表視圖而不是列表視圖包含可擴展列表視圖,當我選擇在擴展列表視圖中的項目我收到一個錯誤如下應用:獲得ArrayIndexBounds異常在BaseAdapter
E/JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
適配器:
public class Daybooklist_adapter extends BaseAdapter {
Context context;
private Activity activity;
private LayoutInflater inflater;
private ArrayList<Daybooklist> daybooklists;
DatabaseHandler databaseHandler;
boolean isListScrolling;
public Daybooklist_adapter(Activity activity, ArrayList<Daybooklist> daybooklists) {
this.activity = activity;
this.daybooklists = daybooklists;
}
@Override
public int getCount() {
return daybooklists.size();
}
@Override
public Object getItem(int i) {
return daybooklists.get(i);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertview, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertview == null)
convertview = inflater.inflate(R.layout.model_daybook_listentry, null);
final TextView day_name = (TextView) convertview.findViewById(R.id.tv_daybook_name);
final TextView day_description = (TextView) convertview.findViewById(R.id.tv_daybook_description);
final TextView day_type = (TextView) convertview.findViewById(R.id.tv_daybook_type);
final TextView day_amount = (TextView) convertview.findViewById(R.id.tv_daybook_amount);
final TextView day_usertype = (TextView) convertview.findViewById(R.id.tv_usertype);
final TextView day_time = (TextView) convertview.findViewById(R.id.tv_daybook_time);
final ImageView day_check = (ImageView) convertview.findViewById(R.id.img_doneall);
final TextView daybook_location = (TextView) convertview.findViewById(R.id.tv_daybook_location);
databaseHandler = new DatabaseHandler(activity);
// getting movie data for the row
final Daybooklist m = daybooklists.get(position);
if (m.getUsertype() != null && !m.getUsertype().isEmpty()) {
if (m.getUsertype().startsWith("farmer") | m.getUsertype().startsWith("singleworker") | m.getUsertype().startsWith("groupworker") | m.getUsertype().startsWith("payvehicle")) {
if (m.getUsertype().startsWith("farmer")) {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
String locat = String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno()));
locat = locat.replaceAll("\\[", "").replaceAll("\\]", "");
Log.e("farmerlocation", locat);
daybook_location.setText(locat);
day_type.setText(m.getType());
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
day_amount.setText("\u20B9" + m.getExtraamt());
if (m.getAmountout().startsWith("0.0") | m.getAmountout().startsWith("0")) {
// day_amount.setTextColor(activity.getResources().getColor(R.color.green));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.INVISIBLE);
} else {
// day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.VISIBLE);
}
day_time.setText(m.getCtime());
} else {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
daybook_location.setText(m.getType());
day_type.setText(m.getType());
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
day_amount.setText("\u20B9" + m.getExtraamt());
if (m.getAmountout().startsWith("0.0") | m.getAmountout().startsWith("0")) {
// day_amount.setTextColor(activity.getResources().getColor(R.color.green));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.INVISIBLE);
} else {
// day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.VISIBLE);
}
day_time.setText(m.getCtime());
}
} else if (m.getUsertype().startsWith("advancefarmer") | m.getUsertype().startsWith("workeradvance") | m.getUsertype().startsWith("kgroupadvance") | m.getUsertype().startsWith("otherexpense") | m.getUsertype().startsWith("vehicle")) {
if (m.getUsertype().startsWith("advancefarmer")) {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
day_type.setText(m.getType());
String locat = String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno()));
locat = locat.replaceAll("\\[", "").replaceAll("\\]", "");
Log.e("farmerlocation", locat);
daybook_location.setText(locat);
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
Log.e("amountout", m.getAmountout());
day_amount.setText("\u20B9" + m.getAmountout());
day_time.setText(m.getCtime());
} else {
day_name.setText(m.getName());
day_description.setText(m.getType());
day_type.setText(m.getType());
daybook_location.setText(m.getDescription());
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
Log.e("amountout", m.getAmountout());
day_amount.setText("\u20B9" + m.getAmountout());
day_time.setText(m.getCtime());
}
} else if (m.getUsertype().startsWith("buyer")) {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
day_amount.setText("\u20B9" + m.getAmountin());
day_type.setText(" ");
day_time.setText(m.getCtime());
daybook_location.setText(m.getType());
}
if (m.getUsertype().startsWith("farmer")) {
day_usertype.setText("F");
day_usertype.setBackgroundResource(R.drawable.textview_farmer);
} else if (m.getUsertype().startsWith("advancefarmer")) {
day_usertype.setText("FA");
day_usertype.setBackgroundResource(R.drawable.textview_farmer);
} else if (m.getUsertype().startsWith("singleworker")) {
day_usertype.setText("W");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("workeradvance")) {
day_usertype.setText("WA");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("groupworker")) {
day_usertype.setText("G");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("kgroupadvance")) {
day_usertype.setText("GA");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("otherexpense")) {
day_usertype.setText("E");
day_usertype.setBackgroundResource(R.drawable.textview_otherexpense);
} else if (m.getUsertype().startsWith("vehicle")) {
day_usertype.setText("V");
day_usertype.setBackgroundResource(R.drawable.textview_vehicle);
} else if (m.getUsertype().startsWith("gsalary")) {
day_usertype.setText("GS");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("isalary")) {
day_usertype.setText("WS");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("payvehicle")) {
day_usertype.setText("VP");
day_usertype.setBackgroundResource(R.drawable.textview_vehicle);
} else if (m.getUsertype().startsWith("buyer")) {
day_usertype.setText("B");
day_usertype.setBackgroundResource(R.drawable.textview_buyer);
}
}
convertview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_UP:
if (!isListScrolling) {
view.setBackgroundColor(Color.LTGRAY);
if (m.getUsertype().startsWith("farmer") | m.getUsertype().startsWith("advancefarmer")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent a = new Intent(activity, FarmerLedgerView_Activity.class);
a.putExtra("farmername", name);
a.putExtra("farmermobno", mobno);
activity.startActivity(a);
} else if (m.getUsertype().startsWith("singleworker") | m.getUsertype().startsWith("workeradvance")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent c = new Intent(activity, WorkerLedger_Activity.class);
c.putExtra("workername", name);
c.putExtra("workermobno", mobno);
activity.startActivity(c);
} else if (m.getUsertype().startsWith("groupworker") | m.getUsertype().startsWith("kgroupadvance")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent g = new Intent(activity, GroupWorkerLedger_Activity.class);
g.putExtra("groupname", name);
g.putExtra("workermobno", mobno);
activity.startActivity(g);
} else if (m.getUsertype().startsWith("isalary")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent d = new Intent(activity, Worker_paymenthistory_Activity.class);
d.putExtra("workername", name);
d.putExtra("workermobno", mobno);
activity.startActivity(d);
} else if (m.getUsertype().startsWith("bsalary")) {
Intent aa = new Intent(activity, WorkerListActivity.class);
activity.startActivity(aa);
} else if (m.getUsertype().startsWith("vehicle") | m.getUsertype().startsWith("payvehicle")) {
Intent s = new Intent(activity, VehicleList_activity.class);
activity.startActivity(s);
} else if (m.getUsertype().startsWith("otherexpense")) {
Intent b = new Intent(activity, OtherExpenseList.class);
activity.startActivity(b);
} else if (m.getUsertype().startsWith("buyer")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent buyer = new Intent(activity, BuyerLedgerViewActivity.class);
buyer.putExtra("buyername", name);
buyer.putExtra("buyermobno", mobno);
activity.startActivity(buyer);
}
}
break;
}
return true;
}
});
return convertview;
}
public void isScrolling(boolean isScroll) {
isListScrolling = isScroll;
Log.e("Innerscrollcheck", String.valueOf(isListScrolling));
}
}在BaseAdapter