views:

217

answers:

1

i want to improve the list view's performance.

this is the code for my getView method in my Adapter?

public View getView(int arg0, View text_view_name, ViewGroup parent) {
    try {

        if (text_view_name == null) {
            text_view_name = mInflater.inflate(
                    R.layout.bs_content_list_item1, null);
            text_view_name.setTag(R.id.text1_detail1, text_view_name
                    .findViewById(R.id.text1_detail1));
            text_view_name.setTag(R.id.text3_detail1, text_view_name
                    .findViewById(R.id.text3_detail1));
            text_view_name.setTag(R.id.eve_img_detail1, text_view_name
                    .findViewById(R.id.eve_img_detail1));
        }

        text1 = (TextView) text_view_name.getTag(R.id.text1_detail1);
        // text2 = (TextView) text_view_name.getTag(R.id.text2);
        text3 = (TextView) text_view_name.getTag(R.id.text3_detail1);
        img = (ImageView) text_view_name.getTag(R.id.eve_img_detail1);
        text1.setText(VAL1[arg0]);
        text3.setText(VAL3[arg0]);

        if (!mBusy) {
            img_value = new URL(VAL4[arg0]);
            mIcon11 =   BitmapFactory.decodeStream(img_value.openConnection()
                    .getInputStream());
            img.setImageBitmap(mIcon11);

            text_view_name.setTag(R.id.eve_img_detail1, null);
        } else {
            img.setImageResource(R.drawable.icon);
            text_view_name.setTag(R.id.eve_img_detail1, text_view_name
                    .findViewById(R.id.eve_img_detail1));
        }

    } catch (Exception e) {
        name = "Exception in MultiLine_bar_details1 getView";
        Log.v(TAG, name + e);
    }
    return text_view_name;
}

this is the code for scrollstatechanged method:

public void onScrollStateChanged(AbsListView view, int scrollState) {
    switch (scrollState) {
    case OnScrollListener.SCROLL_STATE_IDLE:
        try {
            MultiLine_bar_details1.mBusy = false;

            int first = view.getFirstVisiblePosition();
            int count = view.getCount();

            for (int i = 0; i < count; i++) {
                ImageView t = (ImageView) view.getChildAt(i);// here getting the ClassCastException
                if (t.getTag(R.id.eve_img_detail1) != null) {

                    MultiLine_bar_details1.img_value = new URL(
                            MultiLine_bar_details1.VAL4[first + i]);

                    MultiLine_bar_details1.mIcon11 = BitmapFactory
                            .decodeStream(MultiLine_bar_details1.img_value
                                    .openConnection().getInputStream());
                    MultiLine_bar_details1.img.setImageBitmap(MultiLine_bar_details1.mIcon11);
                    t.setTag(R.id.eve_img_detail1, null);
                }
            }
        } catch (Exception e) {
            Log.v(TAG, "Idle" + e);
        }

        // mStatus.setText("Idle");
        break;
    case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
        MultiLine_bar_details1.mBusy = true;

        break;
    case OnScrollListener.SCROLL_STATE_FLING:
        MultiLine_bar_details1.mBusy = true;
        break;
    }
}

getting the Exception in Idle state:

05-03 16:47:15.201: VERBOSE/BS_Bars(258): Idlejava.lang.ClassCastException: android.widget.LinearLayout

this is very complicated for me to get the output properly. actually i have the listview with custom adapter. that icons makes the listview scroll very slow.i am getting the images for icons from the image urls. upto this(above code) i can improve the scroll performance of my list view. but the image icons are not proper in the corresponding order. its dynamically changing when i scroll the listview..

i refered the commonsware busy coder guide and this blog.

EDIT: My very Big question is "How can we access the image view in scrollstatechanged using the parameter AbsListView? "

what is the problem in it? how to do it better? Any Idea?

+1  A: 

What is the top-level view in bs_content_list_item1.xml? You are casting the result of ListView.getChildAt(i) to an ImageView, and it looks like it's not an ImageView.

Romain Guy
yep. but how can i cast that image view?? bs_content_list_item1.xml has the content of the list view. the main listview in the main.xml file.
Praveen Chandrasekaran