CursorAdpter를 사용하는 매우 느린 ListView

춤추는

나는 채우기하고 ListView데이터베이스에서 커서 결과 세트를 수신하는 사용자 정의 커서 어댑터와 함께. 20 개의 뷰만 표시하는 데 최대 10-12 초가 걸릴 수 있습니다!

여기입니다 CursorAdater의 커서가의 일련의 문자열과 기본 64 이미지 표현을 공급 클래스 텍스트 뷰이미지 뷰 각 뷰는 :

    public void bindView(View v, Context context, Cursor c) {
            String diveSite = c.getString(c.getColumnIndexOrThrow(diveDataBase.KEY_DIVESITE));
            String date = c.getString(c.getColumnIndexOrThrow(diveDataBase.KEY__DIVEDATE));
            String diveNumber= c.getString(c.getColumnIndexOrThrow(diveDataBase.KEY__DIVENUMBER));
            String diveImagePath = c.getString(c.getColumnIndex(diveDataBase.KEY_DIVEPICTURE));
            String rating = c.getString(c.getColumnIndexOrThrow(diveDataBase.KEY_DIVERATING));

            c.moveToLast();
            noOfRows = Integer.parseInt(c.getString(c.getColumnIndex(diveDataBase.KEY__DIVENUMBER)));


            /**
             * Next set the dive site name
             */

            TextView title_text = (TextView) v.findViewById(R.id.tv_DiveSiteListView);
            if (title_text!= null) {
                title_text.setText(diveSite);
            }

            /**
             * Set Date of dive in smaller textView font
             */

            TextView date_text = (TextView) v.findViewById(R.id.tv_diveDateList);
            if (date_text!= null) {
                date_text.setText(date);
            }       

            /**
             * Display the dive number in larger red font
             */

            TextView dive_no = (TextView) v.findViewById(R.id.tv_diveNumberListView);
            if (diveNumber!= null  ) {
                dive_no.setText(diveNumber+"/"+noOfRows);//+1 as rows start at zero
            }


            /*
             * Display the rating of the dive
             */
            RatingBar  bar = (RatingBar) v.findViewById(R.id.ratingBarListView);
            bar.setNumStars(5);

            bar.setRating( Float.parseFloat(rating));
            /**
             * Display the image only of image not null
             * First get image from Strimg pathname as a file, then convert to Bitmap and resize
             * 
             */

            ImageView displayImage = (ImageView) v.findViewById(R.id.iv_list_image);

 //set image here once taken form external string path, and resized bitmap conversion

            imagePathFile = new File(diveImagePath); 
            try {
                FileInputStream streamIn = new FileInputStream(imagePathFile);
                Bitmap bitmap = BitmapFactory.decodeStream(streamIn);//retrun null if can't convert

                if(bitmap!=null){
                    displayImage.setBackground(null);
                    resizedImage = reSizeImage(bitmap);

                    displayImage.setImageBitmap(resizedImage);


                }else{

                    displayImage.setBackgroundResource(R.drawable.logdive3);
                }

            } 

            catch (FileNotFoundException e) {
                e.printStackTrace();


            }//end try catch

            }//end newView 

그리고 List-view 클래스에서 커서는 비동기 클래스 의 do-in-background 메소드에서 얻어지며 어댑터는 on-post-execute에 설정됩니다.

@Override
        protected Cursor doInBackground(Void... params) {
            // get the cursor from database

                        ViewListOfDives.data = new diveDataBase(ViewListOfDives.this);
                        ViewListOfDives.data.open();
                        // get cursor object holding all data, use a asynch inner class to load 
                        cursor = data.getCursorData();


                        //ViewListOfDives.data.close();
            return cursor;
        }

//set the adapter to list view

@Override
        protected void onPostExecute(Cursor cursor) {

                        //check if data available
                        if(cursor!=null && cursor.getCount()>0){
                        // get customised array adoater list
                        adapter = new ItemAdapter(ViewListOfDives.this, cursor);
                        }else{

                                //display o dives in data base message and finish this activity
                                displayDialog();

                        }
                        ViewListOfDives.this.setListAdapter(adapter);
                        ViewListOfDives.data.close();
            super.onPostExecute(cursor);
            // dispose dialog
                        if(pd.isShowing()){
                                    pd.dismiss();
                        }
        }

온라인 할당량을 조사해 왔으므로 성능 최적화 커서 어댑터에 대해 많은 것을 찾을 수 없으므로 모든 입력을 많이 주시면 감사하겠습니다 !!

편집 : 이미지 크기를 조정하는 데 사용하는 방법 포함 :

public Bitmap reSizeImage(Bitmap bitmapImage) {
            // resize bitmap image passed and rerun new one
            Bitmap resizedImage = null;
            float factorH = h / (float) bitmapImage.getHeight();
            float factorW = w / (float) bitmapImage.getWidth();
            float factorToUse = (factorH> factorW)? factorW : factorH;
            try {
                resizedImage = Bitmap.createScaledBitmap(bitmapImage,
                        (int) (bitmapImage.getWidth() * factorToUse),
                        (int) (bitmapImage.getHeight() * factorToUse), false);
            } catch (IllegalArgumentException e) {
                Log.d(TAG, "Problem resizing Image @Line 510+");
                e.printStackTrace();
            }
            Log.d(TAG,
                    "in resixed, value of resized image: "
                            + resizedImage.toString());
            return resizedImage;
        }// end reSize

여기서 h와 w :

 // for image resizing
        static int w = 250;
        static int h = 280;

편집 : 기본 64에서 비트 맵으로의 변환을 처리하기 위해 비동기 클래스를 작성한 다음 실행 후 이미지보기가 비트 맵으로 설정됩니다. 이 내부 클래스는 cursoradpter 클래스의 bindView 메서드에서 호출됩니다. 문제는 이제 마지막보기 만 이미지로 채워집니다 !!

 //asynch class to load nase 64 image and convert to bitmap and set imageview 

            private class getBitmapImage extends AsyncTask<String, Void, Bitmap>{

                @Override
                protected Bitmap doInBackground(String... imagePath) {

                    // get image path and decode to bitmap
                    String diveImagePath = imagePath[0];
                    //String diveImagePath = c.getString(c.getColumnIndex(diveDataBase.KEY_DIVEPICTURE));
                     File imagePathFile = new File(diveImagePath); 
                     try {
                            FileInputStream streamIn = new FileInputStream(imagePathFile);
                             bitmap = BitmapFactory.decodeStream(streamIn);//retrun null if cant convert
                }catch (FileNotFoundException e) {

                    e.printStackTrace();
                    //Toast.makeText(context, "No Image Found!! Usimng default", Toast.LENGTH_LONG).show();

                }//end try catch

                    return bitmap;

                }//end do in background


                @Override
                protected void onPostExecute(Bitmap bitmap) {

                    if(bitmap!=null){
                        displayImage.setBackground(null);
                        resizedImage = reSizeImage(bitmap);

                        displayImage.setImageBitmap(resizedImage);


                    }else{
                        //Toast.makeText(context, "No Image Found!! Usimng default", Toast.LENGTH_LONG).show();
                        displayImage.setBackgroundResource(R.drawable.logdive3);
                    }

                }//end onPOstExecute
            }//end getBitmap asynch

이 내부 클래스는 CursorAdpter 클래스의 bindView 메서드에서 호출됩니다.

//get bitmap image from base 64 string, and set to image view using asynch class thread
             new getBitmapImage().execute(diveImagePath);
네임 스페이스
  1. 먼저 화면에 텍스트를 넣으십시오. 로드 중임을 보여주는 기본 드로어 블일 수 있습니다.

  2. 파일에서 20 개의 비트 맵을로드하는 데는 최소한 몇 초가 걸립니다. 비동기 적으로로드해야합니다 (목록보기를 채우는 스레드에서). UI 스레드 만 imageview를 설정할 수 있지만 대부분의 작업 인 작업자 스레드에서 비트 맵을로드 할 수 있습니다.

  3. 또한 표시 할 수있는 것보다 높은 해상도로로드하지 않도록 샘플링을 사용하여 비트 맵을로드해야합니다. 그렇지 않으면 필요한 것보다 더 많은 데이터를 읽게됩니다.

큰 비트 맵을 효율적으로로드하는 방법 은 Android 튜토리얼참조하십시오 .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

GROUP BY를 사용하는 MySQL의 매우 느린 하위 쿼리

분류에서Dev

매우 느린 Codeigniter 웹 사이트를 개선하는 방법

분류에서Dev

Eloquent를 사용할 때 매우 느린 쿼리 whereNotIn

분류에서Dev

매우 느린 Windows 10 UI를 해결하는 방법

분류에서Dev

LIMIT에도 불구하고 사용자 정의 함수를 사용하는 MySQL 매우 느린 쿼리

분류에서Dev

xampp에서 매우 느린 PHP를 사용하여 파일 업로드

분류에서Dev

JestClient를 사용한 ElasticSearch 쿼리가 매우 느린 것 같습니다.

분류에서Dev

매우 느린 파이썬 코드 문제를 해결하는 방법

분류에서Dev

EV 코드는 매우 느린 서명

분류에서Dev

DataBinding을 사용하여 매우 느린 ListBox 채우기

분류에서Dev

Ubuntu 16.04의 LibreOffice는 내 모든 CPU를 사용합니다-매우 느린 스크롤링

분류에서Dev

매우 느린 dnf

분류에서Dev

.Include를 사용하는 Entity Framework .ToList ()가 매우 느린 이유는 무엇이며 어떻게 속도를 높일 수 있습니까?

분류에서Dev

매우 느린 거대한 데이터베이스를 사용한 Neo4J 쿼리

분류에서Dev

매우 느린 ExecuteNonQuery (저장 프로 시저) 대 SQL Server Management Studio를 사용한 빠른 실행

분류에서Dev

대형 객체에 json 빌더를 사용할 때 IntelliJ 매우 느린 업데이트

분류에서Dev

SimpleMembershipProvider를 사용하는 .NET MVC에서 사용자 SELECT가 매우 느림

분류에서Dev

C # asp.net에서 GridView를 사용하여 느린 데이터 채우기

분류에서Dev

CONNECT BY LEVEL을 사용할 때 매우 느린 쿼리

분류에서Dev

Windows 8 매우 높은 디스크 사용량 및 느린 IO

분류에서Dev

Eclipse의 높은 CPU 사용량 및 매우 느린 성능

분류에서Dev

이 짧지 만 매우 느린 Python 루프를 어떻게 최적화 하시겠습니까?

분류에서Dev

매우 느린 참조 일치를 기반으로 두 행을 하나로 결합

분류에서Dev

비디오 재생 변경은 FFMPEG android java 사전 컴파일 라이브러리를 사용하여 매우 느린 프로세스입니다.

분류에서Dev

C-API를 통해 매우 느린 SQLite

분류에서Dev

느린 마우스를 고치는 방법?

분류에서Dev

NOW ()를 사용하는 MySQL 업데이트가 매우 느립니다.

분류에서Dev

codeigniter 응용 프로그램의 매우 느린 성능 방지

분류에서Dev

이미지가 많고 매우 느린 웹 사이트

Related 관련 기사

  1. 1

    GROUP BY를 사용하는 MySQL의 매우 느린 하위 쿼리

  2. 2

    매우 느린 Codeigniter 웹 사이트를 개선하는 방법

  3. 3

    Eloquent를 사용할 때 매우 느린 쿼리 whereNotIn

  4. 4

    매우 느린 Windows 10 UI를 해결하는 방법

  5. 5

    LIMIT에도 불구하고 사용자 정의 함수를 사용하는 MySQL 매우 느린 쿼리

  6. 6

    xampp에서 매우 느린 PHP를 사용하여 파일 업로드

  7. 7

    JestClient를 사용한 ElasticSearch 쿼리가 매우 느린 것 같습니다.

  8. 8

    매우 느린 파이썬 코드 문제를 해결하는 방법

  9. 9

    EV 코드는 매우 느린 서명

  10. 10

    DataBinding을 사용하여 매우 느린 ListBox 채우기

  11. 11

    Ubuntu 16.04의 LibreOffice는 내 모든 CPU를 사용합니다-매우 느린 스크롤링

  12. 12

    매우 느린 dnf

  13. 13

    .Include를 사용하는 Entity Framework .ToList ()가 매우 느린 이유는 무엇이며 어떻게 속도를 높일 수 있습니까?

  14. 14

    매우 느린 거대한 데이터베이스를 사용한 Neo4J 쿼리

  15. 15

    매우 느린 ExecuteNonQuery (저장 프로 시저) 대 SQL Server Management Studio를 사용한 빠른 실행

  16. 16

    대형 객체에 json 빌더를 사용할 때 IntelliJ 매우 느린 업데이트

  17. 17

    SimpleMembershipProvider를 사용하는 .NET MVC에서 사용자 SELECT가 매우 느림

  18. 18

    C # asp.net에서 GridView를 사용하여 느린 데이터 채우기

  19. 19

    CONNECT BY LEVEL을 사용할 때 매우 느린 쿼리

  20. 20

    Windows 8 매우 높은 디스크 사용량 및 느린 IO

  21. 21

    Eclipse의 높은 CPU 사용량 및 매우 느린 성능

  22. 22

    이 짧지 만 매우 느린 Python 루프를 어떻게 최적화 하시겠습니까?

  23. 23

    매우 느린 참조 일치를 기반으로 두 행을 하나로 결합

  24. 24

    비디오 재생 변경은 FFMPEG android java 사전 컴파일 라이브러리를 사용하여 매우 느린 프로세스입니다.

  25. 25

    C-API를 통해 매우 느린 SQLite

  26. 26

    느린 마우스를 고치는 방법?

  27. 27

    NOW ()를 사용하는 MySQL 업데이트가 매우 느립니다.

  28. 28

    codeigniter 응용 프로그램의 매우 느린 성능 방지

  29. 29

    이미지가 많고 매우 느린 웹 사이트

뜨겁다태그

보관