CustomListAdapter Problem in Android? How???

Posted by Praveen Chandrasekaran on Stack Overflow See other posts from Stack Overflow or by Praveen Chandrasekaran
Published on 2010-05-03T11:08:20Z Indexed on 2010/05/03 11:18 UTC
Read the original article Hit count: 374

Filed under:
|
|

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);
                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;
    }
}

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.

My very Big question is "How can we access the single view in scrollstatechanged parameter AbsListView? "

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

© Stack Overflow or respective owner

Related posts about android

Related posts about listview