saa
saa

Reputation: 1568

How can i smooth listView scrolling?

I am writing a media player application using Media extractor API. So my decoder decodes the data and shows content on surface. This is working fine. I have one list view. When i scroll this listview, it showing effect on decoder thread. So i am getting some disturbance. How can i resolve that. Is there any way to run my listView Adapter( getView() method) on separate thread? I saw this link. It may not helpful to me. http://developer.android.com/training/improving-layouts/smooth-scrolling.html Because My list item contain only one textView.

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView txt_Effects;
        ImageView proImage;
        if(convertView == null){
            LayoutInflater inflater= (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView= inflater.inflate(R.layout.row_listview, null);
            txt_Effects= (TextView)convertView.findViewById(R.id.txt_row);
            proImage= (ImageView)convertView.findViewById(R.id.proImage_row);
        }
        else{
            txt_Effects= (TextView)convertView.findViewById(R.id.txt_row);
            proImage= (ImageView)convertView.findViewById(R.id.proImage_row);
        }

        txt_Effects.setText(data[position]);
        txt_Effects.setTextColor(Color.WHITE);
        proImage.setVisibility(View.GONE);

        if(position == previousSelectionIndex){
            txt_Effects.setTextColor(Color.MAGENTA);
            prevSelectedTextView= txt_Effects;
        }

        if(position>= startProIndex && position <= endProIndex){
            proImage.setVisibility(View.VISIBLE);
        }



        return convertView;
    }

Upvotes: 0

Views: 400

Answers (2)

SMR
SMR

Reputation: 6736

You may want to use the ViewHolder pattern to improved the performance of loading your list items. Refer the following:

Android ViewHolder Pattern Example

Holder Pattern

Hope it helps.

Upvotes: 2

Aleksey
Aleksey

Reputation: 239

You should perform all "heavy" operations outside of getView() method. Consider using AsyncTask or ThreadPool for doing your "decoding" and then update your ListView in the UI thread.

Upvotes: 2

Related Questions