自定义列表视图在新项目生成和滚动时卡住

时间:2016-08-11 12:59:54

标签: android listview custom-lists

我有一个问题。我有自定义listView,它有很多子,并且还有另一个自定义列表视图。在listView中显示的所有数据都来自数据库。我的问题是,当我滚动我的主ListView它卡住了一段时间然后滚动。我在这里上传了我的所有代码。

我的主要活动课程:

public class TransactionListMonthWise<DisplayYear> extends TopParentActivity {

ListView statement;
ArrayList<DisplayMonth> status;
ArrayList<DisplayYear> yearstatus;
addBankTransactionList mAdapter;
TextView tvBankName, tvBalance, tvBankAccNoForHistory;
String monthname;
String monthName;
int yearName;
String bankname, amount, accno;
Date theDate;
String currencySymbl, cur_sym;
EPreferences epref;
String TotalBalance, BankBalance, finalTotalIncome;
Toolbar toolbarTransactionListMonthWise;
boolean loadingMore = false;
int itemsPerPage = 2;
DisplayMonth monthNameInAdapter;
int month;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transaction_monthwise);

    bindview();
    init();
    addListener();
}

private void init() {

    epref = EPreferences.getInstance(TransactionListMonthWise.this);
    getPrefData();
    Intent intent = getIntent();
    bankname = intent.getStringExtra("NAME");
    tvBankName.setText(bankname);

    TotalBalance = String.valueOf(intent.getDoubleExtra("BALANCE", 0.0));

    BankBalance = new BigDecimal(TotalBalance).toPlainString();
    DecimalFormat decimalFormatIncome = new DecimalFormat("0.#");
    finalTotalIncome = decimalFormatIncome.format(Double
            .valueOf(TotalBalance));

    tvBalance.setText(currencySymbl
            + " "
            + String.format("%,.00f",
                    (double) Double.parseDouble(finalTotalIncome)));

    // tvBalance.setText(amount + " " + currencySymbl);

    Log.i("symbol", currencySymbl);
    accno = intent.getStringExtra("ACCNO");
    status = new ArrayList<DisplayMonth>();
    yearstatus = new ArrayList<DisplayYear>();
    tvBankAccNoForHistory.setText("xxxxx"
            + intent.getStringExtra("ACC_NUMBER"));
    Utils.BANK_ACC_NUM = intent.getStringExtra("ACC_NUMBER");
    Utils.BANK_NAME_DISP = bankname;
    setSupportActionBar(toolbarTransactionListMonthWise);
    this.toolbarTransactionListMonthWise
            .setNavigationIcon(R.drawable.ic_arrow_back_white100);
    getSupportActionBar().setTitle(bankname + " History");
}

private void bindview() {
    toolbarTransactionListMonthWise = (Toolbar) findViewById(R.id.toolbarTransactionListMonthWise);
    statement = (ListView) findViewById(R.id.list_transaction_view);
    tvBankName = (TextView) findViewById(R.id.tvBankNameForHistory);
    tvBalance = (TextView) findViewById(R.id.tvNetBalanceForHistory);
    tvBankAccNoForHistory = (TextView) findViewById(R.id.tvBankAccNoForHistory);
}

private void addListener() {

    statement.setOnScrollListener(new AbsListView.OnScrollListener() {

        int mLastFirstVisibleItem;
        boolean mIsScrollingUp;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollstate) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {

            int lastInScreen = firstVisibleItem + visibleItemCount;
            if ((lastInScreen == totalItemCount)) {
                new MailSender().execute();
            }
        }
    });

}

@Override
public void onBackPressed() {
    super.onBackPressed();
    Intent intent = new Intent(TransactionListMonthWise.this,
            BankList.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
}

private String getMonth(int month1) {
    switch (month1) {
    case 1:
        monthname = "Jan";
        break;

    case 2:
        monthname = "Feb";
        break;
    case 3:
        monthname = "Mar";
        break;
    case 4:
        monthname = "Apr";
        break;
    case 5:
        monthname = "May";
        break;
    case 6:
        monthname = "Jun";
        break;
    case 7:
        monthname = "Jul";
        break;
    case 8:
        monthname = "Aug";
        break;
    case 9:
        monthname = "Sep";
        break;
    case 10:
        monthname = "Oct";
        break;
    case 11:
        monthname = "Nov";
        break;
    case 12:
        monthname = "Dec";
        break;

    default:
        break;
    }
    return monthname;
}

private int getYear(int years) {
    switch (years) {
    case 1:
        years = 2011;
        break;

    case 2:
        years = 2012;
        break;
    case 3:
        years = 2013;
        break;
    case 4:
        years = 2014;
        break;
    case 5:
        years = 2015;
        break;
    case 6:
        years = 2016;
        break;

    default:
        break;
    }
    return years;
}

private void getPrefData() {
    cur_sym = epref.getPreferencesStr(epref.KEY_CURRENCY, "India");

    Log.d("vaaaaa", " == " + cur_sym);

    if (cur_sym.equalsIgnoreCase("India")) {
        currencySymbl = getResources().getString(R.string.India);

    } else if (cur_sym.equalsIgnoreCase("US")) {
        currencySymbl = getResources().getString(R.string.United_States);
    } else if (cur_sym.equalsIgnoreCase("Japan")) {
        currencySymbl = getResources().getString(R.string.Japan);
    } else if (cur_sym.equalsIgnoreCase("England")) {
        currencySymbl = getResources().getString(R.string.England_pound);
    } else if (cur_sym.equalsIgnoreCase("Costa Rica")) {
        currencySymbl = getResources().getString(R.string.Costa);
    } else if (cur_sym.equalsIgnoreCase("UK")) {
        currencySymbl = getResources().getString(R.string.United);
    } else if (cur_sym.equalsIgnoreCase("Phillipines")) {
        currencySymbl = getResources().getString(R.string.Philippines);
    } else if (cur_sym.equalsIgnoreCase("Mangolia")) {
        currencySymbl = getResources().getString(R.string.Macedonia);
    } else if (cur_sym.equalsIgnoreCase("Australia")) {
        currencySymbl = getResources().getString(R.string.Australia);
    } else if (cur_sym.equalsIgnoreCase("Europ")) {
        currencySymbl = getResources().getString(R.string.Euro);
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
    }
    return super.onOptionsItemSelected(item);
}

public class MailSender extends AsyncTask<Void, Integer, Integer> {
    Dialog progress;

    @SuppressLint("ResourceAsColor")
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progress = new Dialog(TransactionListMonthWise.this,
                R.style.AppDialogExit);
        progress.requestWindowFeature(Window.FEATURE_NO_TITLE);
        progress.show();
        progress.setContentView(R.layout.custom_loading_dialog);
        TextView tv = (TextView) progress.findViewById(R.id.tv);
        tv.setText("Mail is sending...");
        progress.setCanceledOnTouchOutside(false);
        progress.setCancelable(false);
    }

    @Override
    protected Integer doInBackground(Void... params) {
        final RelativeLayout footerView = (RelativeLayout) findViewById(R.id.loadItemsLayout_recyclerView);

        Calendar cal = Calendar.getInstance();

        month = cal.get(Calendar.MONTH) + 1;
        // int year = cal.get(Calendar.YEAR) - 10;
        int currentYear = cal.get(Calendar.YEAR);

        Log.d("viewMonths", "month is" + month + " " + currentYear);

        for (int j = month; j > 0; j--) {

            monthNameInAdapter = new DisplayMonth();
            monthName = getMonth(j);
            monthNameInAdapter.setMonth(monthName);
            status.add(monthNameInAdapter);

        }

        mAdapter = new addBankTransactionList(getApplicationContext(),
                month, status, bankname, accno, currentYear, amount);

        return 0;
    }

    @Override
    protected void onPostExecute(Integer result) {
        super.onPostExecute(result);
        // progress.dismiss();
        if (progress != null) {
            progress.dismiss();
            progress = null;
        }
        try {
            statement.setAdapter(mAdapter);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
}

主Xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
android:gravity="center"
android:orientation="vertical" >

<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbarTransactionListMonthWise"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="?colorPrimary"
    android:minHeight="?actionBarSize"
    android:paddingRight="10dp"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >
</android.support.v7.widget.Toolbar>

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    card_view:cardCornerRadius="5dp"
    card_view:cardUseCompatPadding="true" >

    <RelativeLayout
        android:id="@+id/rlBankNameAndBalance"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@color/green_100"
        android:clickable="true"
        android:gravity="right"
        android:orientation="vertical"
        android:paddingLeft="@dimen/main_list_data_disp_padding_left"
        android:paddingRight="@dimen/main_list_data_disp_padding_right"
        android:paddingTop="@dimen/main_list_data_disp_padding_top" >

        <TextView
            android:id="@+id/tvBankNameForHistory"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/iconId"
            android:text="@string/BankBalance"
            android:textColor="@color/gray_900"
            android:textSize="@dimen/main_list_data_disp_text_size" />

        <TextView
            android:id="@+id/tvBankAccNoForHistory"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tvBankNameForHistory"
            android:text="@string/BankBalance"
            android:textColor="@color/gray_500"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/tvNetBalanceForHistory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:textColor="@color/gray_900"
            android:textSize="@dimen/main_list_data_disp_text_size" />
    </RelativeLayout>
</android.support.v7.widget.CardView>

<ListView
    android:id="@+id/list_transaction_view"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_margin="2dp"
    android:scrollbars="none" />

<include
    android:id="@+id/loadItemsLayout_recyclerView"
    android:layout_width="fill_parent"
    android:layout_height="110dp"
    android:layout_alignParentBottom="true"
    layout="@layout/progress_layout"
    android:visibility="gone" />

主适配器类:

public class addBankTransactionList extends BaseAdapter {

// Activity activityCategory;
static ArrayList<DisplayMonth> monthName;
// ArrayList<DisplayYear> yearName;
ArrayList<Expense> expense;
ArrayList<Income> incomes, Arr;
@SuppressWarnings("rawtypes")
ArrayList<String> arrDateDebit, arrDateCredit;
ArrayList<Double> arrAmountDebit, arrAmountCredit;
Context contextAddBank;
int CurrentMonth;
String bankNameForMatch, months, allyear, SystemMonthInString, amount,
        bankAccNoForMatch;
int monthname;
String currencySymbl, cur_sym;
String date = "", thirdYear;
String monthNameInString;
EPreferences epref;
ArrayList<Income> tempIncomeses = new ArrayList<Income>();
String dateIncome, dateExpense;
Double expenseAmount, incomeAmount;
DataBaseAdapter adapter;
// private String ;
int monthNameInStringExpense, monthNameInStringIncome;
int yr, year;
int monthsInIntIncome, dateInIntIncome, yearInIntIncome,
        monthsInIntExpense;
String convertDate;
// private ArrayList<Income> tempincomes = new ArrayList<Income>();
List list;
Date date1;
String emptyExpenseAmount, emptyIncomeAmount;
FilterData data;
private String bankname, accno;
public static Boolean isScrolling = true;

public static class ViewHolder {

    public TextView tvDate, tvIncomeMoney, tvExpenseMoney,
            tvRecordnotFound, tvIncomeSymblIncomeDisp, tvTransactionType,
            tvTransactionDate, tvTransactionAmount, tvMoneyCurrencyExpense,
            tvMoneyCurrencyIncome;
    ListView rvList;

}

public addBankTransactionList(Context mcontext, int month,
        ArrayList<DisplayMonth> status, String bankname, String bankAccNo,
        int year, String amt) {
    super();

    this.contextAddBank = mcontext;
    monthName = status;
    CurrentMonth = month;
    bankNameForMatch = bankname;
    bankAccNoForMatch = bankAccNo;
    yr = year;
    amount = amt;
}

public boolean setListViewHeightBasedOnItems(ListView listView) {

    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter != null) {

        int numberOfItems = listAdapter.getCount();

        Log.i("TotalRecord", numberOfItems + "");
        int totalItemsHeight = 0;
        for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
            View item = listAdapter.getView(itemPos, null, listView);
            item.measure(0, 0);
            totalItemsHeight += item.getMeasuredHeight();
        }

        int totalDividersHeight = listView.getDividerHeight()
                * (numberOfItems - 1);

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalItemsHeight + totalDividersHeight;
        listView.setLayoutParams(params);
        listView.requestLayout();
        listView.setClickable(false);
        listView.setEnabled(false);
        return true;

    } else {
        return false;
    }
}

private void getPrefData() {
    cur_sym = epref.getPreferencesStr(epref.KEY_CURRENCY, "India");

    Log.d("vaaaaa", " == " + cur_sym);

    if (cur_sym.equalsIgnoreCase("India")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.India);
    } else if (cur_sym.equalsIgnoreCase("US")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.United_States);
    } else if (cur_sym.equalsIgnoreCase("Japan")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.Japan);
    } else if (cur_sym.equalsIgnoreCase("England")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.England_pound);
    } else if (cur_sym.equalsIgnoreCase("Costa Rica")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.Costa);
    } else if (cur_sym.equalsIgnoreCase("UK")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.United);
    } else if (cur_sym.equalsIgnoreCase("Phillipines")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.Philippines);
    } else if (cur_sym.equalsIgnoreCase("Mangolia")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.Macedonia);
    } else if (cur_sym.equalsIgnoreCase("Australia")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.Australia);
    } else if (cur_sym.equalsIgnoreCase("Europ")) {
        currencySymbl = contextAddBank.getResources().getString(
                R.string.Euro);
    }
}

private int getMonthName(String month1) {
    switch (month1.toLowerCase().toString()) {

    case "Jan":
        monthname = 1;
        break;

    case "Feb":
        monthname = 2;
        break;

    case "Mar":
        monthname = 3;
        break;

    case "Apr":
        monthname = 4;
        break;

    case "May":
        monthname = 5;
        break;

    case "Jun":
        monthname = 6;
        break;

    case "Jul":
        monthname = 7;
        break;

    case "Aug":
        monthname = 8;
        break;

    case "Sep":
        monthname = 9;
        break;

    case "Oct":
        monthname = 10;
        break;

    case "Nov":
        monthname = 11;
        break;

    case "Dec":
        monthname = 12;
        break;

    default:
        break;
    }
    return monthname;
}

@Override
public int getCount() {
    return monthName.size();
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int arg0) {
    return 0;
}

@Override
public View getView(int position, View conView, ViewGroup parent) {

    ViewHolder vh;
    if (conView == null) {
        conView = LayoutInflater.from(contextAddBank).inflate(
                R.layout.transaction_list, null, false);
        vh = new ViewHolder();
        vh.tvDate = (TextView) conView.findViewById(R.id.tvDate);
        vh.rvList = (ListView) conView
                .findViewById(R.id.lvDisplayExpenseList);
        vh.tvIncomeMoney = (TextView) conView
                .findViewById(R.id.tvIncomeMoney);
        vh.tvExpenseMoney = (TextView) conView
                .findViewById(R.id.tvExpenseMoney);
        vh.tvRecordnotFound = (TextView) conView
                .findViewById(R.id.tvrecordnotFound);
        vh.tvIncomeSymblIncomeDisp = (TextView) conView
                .findViewById(R.id.tvIncomeSymblIncomeDisp);
        vh.tvMoneyCurrencyExpense = (TextView) conView
                .findViewById(R.id.tvMoneyCurrencyExpense);
        vh.tvMoneyCurrencyIncome = (TextView) conView
                .findViewById(R.id.tvMoneyCurrencyIncome);
        adapter = new DataBaseAdapter(contextAddBank);
        arrDateDebit = new ArrayList<String>();
        arrAmountDebit = new ArrayList<Double>();
        arrDateCredit = new ArrayList<String>();
        arrAmountCredit = new ArrayList<Double>();
        epref = EPreferences.getInstance(contextAddBank);
        incomes = new ArrayList<Income>();
        expense = new ArrayList<Expense>();

        getPrefData();
        vh.tvMoneyCurrencyExpense.setText(currencySymbl);
        vh.tvMoneyCurrencyIncome.setText(currencySymbl);
        adapter.open();
        adapter.close();
        conView.setTag(vh);
    } else {
        vh = (ViewHolder) conView.getTag();
    }
    expense.clear();
    incomes.clear();

    arrDateCredit.clear();
    arrAmountCredit.clear();
    arrDateDebit.clear();
    arrAmountDebit.clear();
    adapter.open();
    // viewHolder.rvList.setAdapter(Adapter);
    incomes = adapter.read_income();
    expense = adapter.read_expense();

    double totalExpense = 0.0;
    double totalIncome = 0.0;
    DisplayMonth month = monthName.get(position);
    vh.tvDate.setText(month.getMonth() + "  " + yr);
    months = month.getMonth();

    Log.d("tagNameAdapter",
            "name is " + bankNameForMatch + ":::" + month.getMonth());

    Log.d("expencesize", "size is " + expense.size());

    // expense = adapter.read_expense_with_bankName(bankNameForMatch,
    // bankAccNoForMatch);

    if (expense.size() > 0) {

        for (int l = 0; l < expense.size(); l++) {

            Log.d("tagbankfil",
                    "" + bankNameForMatch + "=="
                            + expense.get(l).getBankname() + " AND "
                            + expense.get(l).getAccno() + "=="
                            + bankAccNoForMatch);

            if (bankNameForMatch.equals(expense.get(l).getBankname())
                    && bankAccNoForMatch.substring(
                            bankAccNoForMatch.length() - 3)
                            .equalsIgnoreCase(
                                    expense.get(l)
                                            .getAccno()
                                            .substring(
                                                    expense.get(l)
                                                            .getAccno()
                                                            .length() - 3))) {

                dateExpense = expense.get(l).getDate();
                expenseAmount = expense.get(l).getAmount();

                Log.i("ExpenseAmount", expenseAmount + ":::::"
                        + dateExpense);

                Calendar calendar = Calendar.getInstance();
                year = calendar.get(Calendar.YEAR);

                StringTokenizer tokensIncome = new StringTokenizer(
                        dateExpense, "-");

                String firstDate = tokensIncome.nextToken();
                String secondMonth = tokensIncome.nextToken();
                thirdYear = tokensIncome.nextToken();

                monthsInIntExpense = Integer.parseInt(secondMonth);

                int totalYear = Integer.parseInt(thirdYear);

                Log.i("MonthNameExpense", totalYear + "");

                Log.i("MonthSplitExpense", firstDate + "  " + secondMonth
                        + "  " + thirdYear);

                // for (int jmon = 0; jmon < expense.size(); jmon++) {

                Log.i("loopTimes", "Check");

                SimpleDateFormat sdfSource = new SimpleDateFormat(
                        "dd-MM-yyyy");

                Date dateVal = null;
                Log.i("axisbankdateval", dateVal + "");
                try {
                    dateVal = sdfSource.parse(dateExpense);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

                SimpleDateFormat sdfDestination = new SimpleDateFormat(
                        "dd-MMM-yyyy");

                convertDate = sdfDestination.format(dateVal);
                String[] parts = convertDate.split("-");
                String transactionMonth = parts[1];
                String transactionYear = parts[2];

                Log.i("allYear", year + "  ");
                monthNameInStringExpense = getMonthName(transactionMonth);

                Log.i("finddate", convertDate + ":::" + transactionMonth
                        + ":::" + monthNameInStringExpense + "::"
                        + transactionYear);

                Log.d("tagmonth", "" + month.getMonth() + " ::: "
                        + transactionMonth + " ---- " + totalYear + "::::"
                        + year);

                if (month.getMonth().contains(transactionMonth)
                        && totalYear == year) {

                    emptyExpenseAmount = vh.tvExpenseMoney.getText()
                            .toString();

                    Log.i("dateAmount", " " + expense.get(l).getAmount()
                            + " " + expense.get(l).getDate());

                    arrDateDebit.add(expense.get(l).getDate());
                    arrAmountDebit.add(expense.get(l).getAmount());

                    totalExpense += expense.get(l).getAmount();

                    DecimalFormat decimalFormatExpense = new DecimalFormat(
                            "0.#");
                    String finalTotalExpense = decimalFormatExpense
                            .format(Double.valueOf(totalExpense));
                    String valTvExpenseAmt = new BigDecimal(
                            finalTotalExpense).toPlainString();

                    vh.tvExpenseMoney.setText(String.format("%,.00f",
                            (double) Double.parseDouble(valTvExpenseAmt))
                            + " " + currencySymbl);

                    if (totalExpense == 0.0) {

                        vh.tvExpenseMoney.setText("0.0");
                        vh.tvMoneyCurrencyExpense.setText(currencySymbl);

                    } else {

                        if (vh.tvRecordnotFound.getVisibility() == View.VISIBLE) {
                            vh.tvRecordnotFound.setVisibility(View.GONE);
                            vh.tvMoneyCurrencyExpense
                                    .setVisibility(View.INVISIBLE);

                            vh.tvExpenseMoney.setText(" " + totalExpense
                                    + " " + currencySymbl);

                            vh.tvMoneyCurrencyExpense
                                    .setText(currencySymbl);
                        }
                    }
                }
            }
        }

    }

    if (incomes.size() > 0) {
        for (int j = 0; j < incomes.size(); j++) {

            Log.d("tagbankfil",
                    "" + bankNameForMatch + "=="
                            + incomes.get(j).getIncome_bankname() + " AND "
                            + incomes.get(j).getIncome_accno() + "=="
                            + bankAccNoForMatch);

            if (bankNameForMatch
                    .equals(incomes.get(j).getIncome_bankname())
                    && bankAccNoForMatch
                            .substring(bankAccNoForMatch.length() - 3)
                            .equalsIgnoreCase(
                                    incomes.get(j)
                                            .getIncome_accno()
                                            .substring(
                                                    incomes.get(j)
                                                            .getIncome_accno()
                                                            .length() - 3))) {

                dateIncome = incomes.get(j).getIncome_date();
                incomeAmount = incomes.get(j).getIncome_amount();

                Log.i("IncomeAmount", incomeAmount + ":::::" + dateIncome);

                Calendar calendar = Calendar.getInstance();
                year = calendar.get(Calendar.YEAR);

                StringTokenizer tokensIncome = new StringTokenizer(
                        dateIncome, "-");

                String firstDate = tokensIncome.nextToken();
                String secondMonth = tokensIncome.nextToken();
                thirdYear = tokensIncome.nextToken();

                monthsInIntIncome = Integer.parseInt(thirdYear);

                int totalYear = Integer.parseInt(thirdYear);

                Log.i("MonthNameIncome", monthsInIntIncome + "  " + ""
                        + monthNameInStringIncome + " " + dateIncome + " "
                        + incomes.size() + "" + totalYear);

                Log.i("MonthSplitIncome", firstDate + "  " + secondMonth
                        + "  " + thirdYear);

                Log.i("loopTimes", "Check");

                SimpleDateFormat sdfSource = new SimpleDateFormat(
                        "dd-MM-yyyy");

                Date dateVal = null;
                Log.i("axisbankdateval", dateVal + "");
                try {
                    dateVal = sdfSource.parse(dateIncome);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

                SimpleDateFormat sdfDestination = new SimpleDateFormat(
                        "dd-MMM-yyyy");

                convertDate = sdfDestination.format(dateVal);

                String[] parts = convertDate.split("-");
                String transactionMonth = parts[1];
                String transactionYear = parts[2];

                monthNameInStringIncome = getMonthName(transactionMonth);

                Log.i("finddate", convertDate + "::" + monthname + "::"
                        + monthNameInStringIncome);

                if (month.getMonth().contains(transactionMonth)
                        && totalYear == year) {

                    emptyIncomeAmount = vh.tvIncomeMoney.getText()
                            .toString();

                    arrDateCredit.add(incomes.get(j).getIncome_date());
                    arrAmountCredit.add(incomes.get(j).getIncome_amount());

                    totalIncome += incomes.get(j).getIncome_amount();

                    DecimalFormat decimalFormatIncome = new DecimalFormat(
                            "0.#");
                    String finalTotalIncome = decimalFormatIncome
                            .format(Double.valueOf(totalIncome));

                    String valTvIncomeAmt = new BigDecimal(finalTotalIncome)
                            .toPlainString();

                    vh.tvIncomeMoney.setText(String.format("%,.00f",
                            (double) Double.parseDouble(valTvIncomeAmt))
                            + " ");

                    vh.tvMoneyCurrencyIncome.setText(currencySymbl);

                    if (totalIncome == 0.0) {

                        vh.tvIncomeMoney.setText("0.0");
                        vh.tvMoneyCurrencyIncome.setText(currencySymbl);

                    } else {

                        if (vh.tvRecordnotFound.getVisibility() == View.VISIBLE) {
                            vh.tvRecordnotFound.setVisibility(View.GONE);

                            vh.tvIncomeMoney.setText(" " + totalIncome
                                    + " " + currencySymbl);
                        }
                    }
                }
            }
        }
        Log.i("currentYear", year + "" + thirdYear);

    }

    CategoryList categoryListAdapter = new CategoryList(contextAddBank,
            arrDateDebit, arrAmountDebit, arrDateCredit, arrAmountCredit);

    vh.rvList.setAdapter(categoryListAdapter);
    setListViewHeightBasedOnItems(vh.rvList);
    vh.rvList.setScrollContainer(true);

    categoryListAdapter.notifyDataSetChanged();

    return conView;
}
}

1 个答案:

答案 0 :(得分:0)

当您向下滚动时,您的应用程序会停滞不前,因为滚动时每次移动都会执行所有处理。每一次将其带回屏幕时,每一行都会运行getView方法的语句,手机没有足够的处理能力来处理所有这些。您需要将所有这些分成不同的类,然后将其加载到较小的数据集中的适配器中,以便它所需要做的就是显示它。基本上,你正在UI(主)线程中进行处理,这很糟糕。

鉴于你们如何嵌套listViews,在宏观方案中更改为expandedListView也会更容易,可以更好地完成工作。这是一个教程:https://www.youtube.com/watch?v=BkazaAeeW1Q