簡體   English   中英

為什么我的Android活動表現如此之慢?

[英]Why is my android activity performing so slow?

從第二個單擊通知活動按鈕,程序立即開始緩慢行動。 這個屏幕由於某種原因需要幾分鍾才能以非常小故障的方式向下滾動。 我該怎么做才能加快和平滑我的通知活動屏幕?

NotificationActivity:

public class NotificationActivity extends BaseActivity {
public static final String TAG = LoginActivity.class.getSimpleName();
private NotificationAdapter notificationAdapter;
private HeaderLayout headerLayout;
private FooterLayout footerLayout;
private SimpleGestureFilter detector;
private ListView mNotificationLv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notification);
    mNotificationLv = (ListView) findViewById(R.id.notification_lv);
    mNotificationLv = (ListView) findViewById(R.id.notification_lv);

    notificationAdapter = new NotificationAdapter(this);
    notificationAdapter.setList(AtlasApplication.lstNotificationModels);
    mNotificationLv.setAdapter(notificationAdapter);

    // Detect touched area
    detector = new SimpleGestureFilter(this,this);
}

@Override
protected void onResume() {
    super.onResume();
    List<NotificationModel> userModelList = AtlasApplication.lstNotificationModels;
    notificationAdapter = new NotificationAdapter(this);
    notificationAdapter.setList(userModelList);
    mNotificationLv.setAdapter(notificationAdapter);
}
}

NotificationAdapter:

public class NotificationAdapter extends BaseAdapter{

private List<NotificationModel> lstNotificationModels;
private SQLiteAdapter sqLiteAdapter;
private Context context;
public NotificationAdapter(Context context) {
    this.context = context; sqLiteAdapter=new SQLiteAdapter(context, this, new Dialog(context));
}

public void setList(List<NotificationModel> genres) {
    this.lstNotificationModels = genres;
    notifyDataSetChanged();
}

private class ViewHolder {
    TextView mNotifiactionTypeTv, mNotifiactionTextTv, mNotifiactionTimeTv;
    LinearLayout rowNotificationLl;
}

public void setRead(int i){
    sqLiteAdapter.updateNotificationStatus(i, "read");
    lstNotificationModels.get(i).setmNotificationStatus("read");
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.row_notification, null);
        holder = new ViewHolder();
        holder.rowNotificationLl = (LinearLayout) convertView.findViewById(R.id.row_notification_ll);
        holder.mNotifiactionTextTv = (TextView) convertView.findViewById(R.id.notification_text_tv);
        holder.mNotifiactionTimeTv = (TextView) convertView.findViewById(R.id.notification_time_tv);
        holder.mNotifiactionTypeTv = (TextView) convertView.findViewById(R.id.notification_type_atv);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    final NotificationModel notificationModel = lstNotificationModels.get(position);
    final String newFullText = sqLiteAdapter.getFullText(notificationModel.getmLawId());

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date currentDate = new Date();
    Date notificationDate = new Date();
    String timeElapsed = "moments ago.";
    try {
        notificationDate = simpleDateFormat.parse(notificationModel.getmNotificationTime().trim());
    } catch(ParseException e){

    }
    long milliElapsed = currentDate.getTime() - notificationDate.getTime() + 14400000;
    if(milliElapsed>=60000){
        long minutesElapsed = milliElapsed/60000;
        timeElapsed = minutesElapsed + " minutes ago.";
        if(minutesElapsed>=60){
            long hoursElapsed = minutesElapsed/60;
            timeElapsed = hoursElapsed + " hours ago.";
            if(hoursElapsed>=24){
                long daysElapsed = hoursElapsed/60;
                timeElapsed = daysElapsed + " days ago.";
                if(daysElapsed>=7){
                    long weeksElapsed = daysElapsed/7;
                    timeElapsed = hoursElapsed + " weeks ago.";
                    if(weeksElapsed>=4){
                        long monthsElapsed = weeksElapsed/4;
                        timeElapsed = monthsElapsed + " months ago.";
                        if(daysElapsed>=365){
                            long yearsElapsed = daysElapsed/365;
                            timeElapsed = yearsElapsed + " years ago.";
                        }
                    }
                }
            }
        }

    }

    holder.mNotifiactionTextTv.setText(Html.fromHtml(notificationModel.getmNotificationText().trim()));
    holder.mNotifiactionTimeTv.setText(timeElapsed);
    if (notificationModel.getmNotificationStatus().equalsIgnoreCase("unread")) {
        convertView.findViewById(R.id.unread_vw).setVisibility(View.VISIBLE);
        holder.rowNotificationLl.setBackgroundResource(R.color.black);
    }
    else {
        convertView.findViewById(R.id.unread_vw).setVisibility(View.GONE);
        holder.rowNotificationLl.setBackgroundResource(R.color.grad_light);
    }

    switch (notificationModel.getmNotificationType().toLowerCase()){
        case "traffic":
            holder.mNotifiactionTypeTv.setBackgroundResource(R.drawable.traffic_noti_bg);
            holder.mNotifiactionTypeTv.setText("f");

            holder.mNotifiactionTypeTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_TRAFFIC;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(0);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }

            });

            holder.mNotifiactionTextTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_TRAFFIC;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(0);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                    catch(Exception e){
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }

            });

            break;
        case "law enforcement":
            holder.mNotifiactionTypeTv.setBackgroundResource(R.drawable.enforcement_noti_bg);
            holder.mNotifiactionTypeTv.setText("c");
            holder.mNotifiactionTypeTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_ENFORCEMENT;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(1);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            holder.mNotifiactionTextTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_ENFORCEMENT;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(1);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                    catch(Exception e){
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }

            });

            break;
        case "alcohol":
            holder.mNotifiactionTypeTv.setBackgroundResource(R.drawable.alcohal_noti_bg);
            holder.mNotifiactionTypeTv.setText("a");
            holder.mNotifiactionTypeTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_ALCOHOL;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(2);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            holder.mNotifiactionTextTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_ALCOHOL;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(2);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                    catch(Exception e){
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }

            });

            break;
        case "taxes":
            holder.mNotifiactionTypeTv.setBackgroundResource(R.drawable.taxes_noti_bg);
            holder.mNotifiactionTypeTv.setText("e");
            holder.mNotifiactionTypeTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_TAXES;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(3);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            holder.mNotifiactionTextTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_TAXES;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(3);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            break;
        case "guns":
            holder.mNotifiactionTypeTv.setBackgroundResource(R.drawable.guns_noti_bg);
            holder.mNotifiactionTypeTv.setText("b");
            holder.mNotifiactionTypeTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_GUNS;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(4);
                        setRead(notificationModel.getmNotificaticationId());
                        AtlasApplication.lstLawsForLocation.get(1).setSelected(true);
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            holder.mNotifiactionTextTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_GUNS;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(4);
                        setRead(notificationModel.getmNotificaticationId());
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                    catch(Exception e){
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            break;
        case "marijuana":
            holder.mNotifiactionTypeTv.setBackgroundResource(R.drawable.marijuana_noti_bg);
            holder.mNotifiactionTypeTv.setText("d");
            holder.mNotifiactionTypeTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        AtlasApplication.MenuTitle = Constants.CAT_MARIJUANA;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(5);
                        setRead(notificationModel.getmNotificaticationId());

                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            holder.mNotifiactionTextTv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {

                        AtlasApplication.MenuTitle = Constants.CAT_MARIJUANA;
                        AtlasApplication.sCategoryModel = AtlasApplication.lstCategoryModels.get(5);
                        setRead(notificationModel.getmNotificaticationId());
                        AtlasApplication.lstLawsForLocation.get(1).setSelected(true);
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    } catch (Exception e) {
                        view.getContext().startActivity(SubMenuActivity.getIntent(view.getContext()));
                    }
                }
            });

            break;
        default:
            break;
    }
    FontLoader.setAtlasFont(holder.mNotifiactionTypeTv);
    FontLoader.setRalewayRegularFont(holder.mNotifiactionTextTv, holder.mNotifiactionTimeTv);

    holder.rowNotificationLl.setId(position);
    holder.rowNotificationLl.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
    return convertView;
}
}

SQLiteAdapter:

public class SQLiteAdapter {
    private static final int DATABASE_VERSION = 1;

   private static String DB_PATH;//= Environment.getExternalStorageDirectory() + "/" + context.getPackageName() + "/";
    private SQLiteDatabase mSqLiteDatabase;
    private Context mContext;
    private Dialog mDialog;
    private SQLiteDbQueryListener sqLiteDbQueryListener;
    private ExceptionHandler exceptionHandler;

    public SQLiteAdapter(Context c, SQLiteDbQueryListener listener, Dialog dialog) {
        mContext = c;
        sqLiteDbQueryListener = listener;
        exceptionHandler = new ExceptionHandler(mContext, "SQLiteAdapter");
        mDialog = dialog;
        DB_PATH = Environment.getExternalStorageDirectory() + "/" + mContext.getPackageName() + "/";
        //call it so db get copied from assets to sdcard
        //call it so db get copied from assets to sdcard
        openToRead();
        close();
    }

public void updateLaw(int lawID, String newSummary, String newFullText){

    int tagID = getTagID(lawID);
    String tagName = getTagName(tagID);
    int categoryID = getCategoryID(tagID);
    String categoryName = getCategoryName(categoryID);
    String location;
        location = getLocationName(getLocationID(lawID));
        if (location.toLowerCase().equals(AtlasApplication.sHometownSelected.getLocationName().toLowerCase())) {
            location = "your current state";
        } else if (location.toLowerCase().equals(AtlasApplication.sHometownSelected.getLocationName().toLowerCase())) {
            location = "your home state";
        }

    openToWrite();

        ContentValues contentValues = new ContentValues();
        contentValues.put(Constants.KEY_SUMMARY, newSummary);
        if(newFullText!=null)
            contentValues.put(Constants.KEY_FULL_TEXT, newFullText);

        mSqLiteDatabase.update(Constants.TABLE_LAW, contentValues, Constants.KEY_LAW_ID + "=" + lawID, null);
    close();
                insertNotification(lawID, categoryName, tagName + " has changed in " + location + ".");

}

public int getCategoryID(int tagID){
    openToRead();
    int categoryID = 0;

    String Query = "SELECT * from " + Constants.TABLE_CATEGORY_TAG;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);
       if (cursor.moveToFirst()) {
            while (cursor.isAfterLast() == false) {
                    if (cursor.getInt(cursor.getColumnIndex(Constants.KEY_TAG_ID)) == tagID) {
                            int indexCategoryID = cursor.getColumnIndex(Constants.KEY_CATEGORY_ID);
                            categoryID = cursor.getInt(indexCategoryID);
                    }
                cursor.moveToNext();
            }
        }
    close();
    return categoryID;
}

public String getCategoryName(int categoryID){
    String categoryName = "";
    openToRead();
    String Query = "SELECT * from " + Constants.TABLE_CATEGORY;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);

        if (cursor.moveToFirst()) {
            while (cursor.isAfterLast() == false) {
            if (cursor.getInt(cursor.getColumnIndex(Constants.KEY_CATEGORY_ID)) == categoryID) {
                        int indexCategoryName = cursor.getColumnIndex(Constants.KEY_CATEGORY_NAME);
                        categoryName = cursor.getString(indexCategoryName);
                }
                cursor.moveToNext();
            }
        }
    close();
    return categoryName.toLowerCase();
}

public int getLocationID(int lawID){
    openToRead();
    String Query = "SELECT * from " + Constants.TABLE_LAW_LOCATION;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);
    int locationID = 0;

    if (cursor.moveToFirst()) {
        while (cursor.isAfterLast() == false) {
            try {
                if(cursor.getInt(cursor.getColumnIndex(Constants.KEY_LAW_ID)) == lawID) {
                    int indexTagID = cursor.getColumnIndex(Constants.KEY_LOCATION_ID);
                    locationID = cursor.getInt(indexTagID);
                }
            } catch (Exception e) {
                exceptionHandler.alert(e, "getLocationID()");
            }
            cursor.moveToNext();
        }
    }
    close();
    return locationID;
}

public String getLocationName(int locationID){
    openToRead();
    String Query = "SELECT * from " + Constants.TABLE_LOCATION;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);
    String locationName = "";

    if (cursor.moveToFirst()) {
        while (cursor.isAfterLast() == false) {
                if(cursor.getInt(cursor.getColumnIndex(Constants.KEY_LOCATION_ID)) == locationID) {
                    int indexTagID = cursor.getColumnIndex(Constants.KEY_LOCATION_NAME);
                    locationName = cursor.getString(indexTagID);
                }
            cursor.moveToNext();
        }
    }

    close();
    return locationName;

}

public int getTagID(int lawID){
    openToRead();
    String Query = "SELECT * from " + Constants.TABLE_LAW_TAG;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);
    int tagID = 0;

    if (cursor.moveToFirst()) {
        while (cursor.isAfterLast() == false) {
            if(cursor.getInt(cursor.getColumnIndex(Constants.KEY_LAW_ID)) == lawID) {
                    int indexTagID = cursor.getColumnIndex(Constants.KEY_TAG_ID);
                    tagID = cursor.getInt(indexTagID);
            cursor.moveToNext();
        }
    }
    close();
    return tagID;
}

public String getTagName(int tagID){
    openToRead();
    String tagName = "";
    String Query = "SELECT * from " + Constants.TABLE_TAG;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);

    if(cursor.moveToFirst()){
        while (cursor.isAfterLast() == false) {
            try {
                if(cursor.getInt(cursor.getColumnIndex(Constants.KEY_TAG_ID)) == tagID) {
                    int indexTagName = cursor.getColumnIndex(Constants.KEY_TAG_NAME);
                    tagName = cursor.getString(indexTagName);
                }
            } catch (Exception e) {
                exceptionHandler.alert(e, "getTagName()");
            }
            cursor.moveToNext();
        }
    }
    close();
    return tagName;
}

public void insertNotification(int lawID, String type, String text){

    openToWrite();
    try {
        ContentValues contentValues = new ContentValues();
        contentValues.put(Constants.KEY_LAW_ID, lawID);
        contentValues.put(Constants.KEY_NOTIFICATION_TYPE, type);
        contentValues.put(Constants.KEY_NOTIFICATION_TEXT, text);
        contentValues.put(Constants.KEY_NOTIFICATION_STATUS, "unread");

        mSqLiteDatabase.insert(Constants.TABLE_NOTIFICATION, null, contentValues);
    }
    catch(Exception e){
        exceptionHandler.alert(e, "insertNotification()");
    }
    close();

}

public void dropNotifications(){
    openToWrite();
    try{
        mSqLiteDatabase.execSQL("DROP TABLE IF EXISTS notification");
    }
    catch(Exception e){

    }
    close();
}

public void updateNotificationStatus(int notificationID, String status){
    openToWrite();

    try {
        ContentValues contentValues = new ContentValues();
        contentValues.put(Constants.KEY_NOTIFICATION_STATUS, status);

        mSqLiteDatabase.update(Constants.TABLE_NOTIFICATION, contentValues, Constants.KEY_NOTIFICATION_ID + "=" + notificationID, null);
    }
    catch(Exception e){
        exceptionHandler.alert(e, "updateNotificationStatus()");
    }
    close();
}

public String getNotificationStatus(int notificationID){
    openToRead();
    String Query = "SELECT * FROM " + Constants.TABLE_NOTIFICATION + " WHERE " + Constants.KEY_NOTIFICATION_ID + "=" + notificationID;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);
    String notificationStatus = "";
    if(cursor.moveToFirst()){
        while (cursor.isAfterLast() == false) {
            try {
                if(cursor.getInt(cursor.getColumnIndex(Constants.KEY_NOTIFICATION_ID)) == notificationID) {
                    int indexNotificationStatus = cursor.getColumnIndex(Constants.KEY_NOTIFICATION_STATUS);
                    notificationStatus = cursor.getString(indexNotificationStatus);
                }
            } catch (Exception e) {
                exceptionHandler.alert(e, "getNotificationStatus()");
            }
            cursor.moveToNext();
        }
    }

    close();

    return notificationStatus;

}

public int getNotificationId(int lawID, String time){

    openToRead();

    int notificationId = 0;
        String query = "SELECT * FROM " + Constants.TABLE_NOTIFICATION +
                " WHERE " + Constants.KEY_NOTIFICATION_TIME + " = " + time;
        Cursor cursor = mSqLiteDatabase.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            while (cursor.isAfterLast() == false) {
                int indexNotificationID = cursor.getColumnIndex(Constants.KEY_NOTIFICATION_ID);
                notificationId = cursor.getInt(indexNotificationID);
            }
    }
    close();

    return notificationId;
}

public List<NotificationModel> getNotificationList(){
    List<NotificationModel> lstNotifications = new ArrayList<NotificationModel>();

    openToRead();

    String Query = "SELECT * from " + Constants.TABLE_NOTIFICATION;
    Cursor cursor = mSqLiteDatabase.rawQuery(Query, null);

    if (cursor.moveToFirst()) {
        while (cursor.isAfterLast() == false) {
            try {
                int indexNotificationID = cursor.getColumnIndex(Constants.KEY_NOTIFICATION_ID);
                int indexLawID = cursor.getColumnIndex(Constants.KEY_LAW_ID);
                int indexNotificationTime = cursor.getColumnIndex(Constants.KEY_NOTIFICATION_TIME);
                int indexNotificationType = cursor.getColumnIndex(Constants.KEY_NOTIFICATION_TYPE);
                int indexNotificationText = cursor.getColumnIndex(Constants.KEY_NOTIFICATION_TEXT);
                int indexNotificationStatus = cursor.getColumnIndex(Constants.KEY_NOTIFICATION_STATUS);

                int notificationID = cursor.getInt(indexNotificationID);
                int lawID = indexLawID;
                String notificationTime = cursor.getString(indexNotificationTime);
                String notificationType = cursor.getString(indexNotificationType);
                String notificationText = cursor.getString(indexNotificationText);
                String notificationStatus = cursor.getString(indexNotificationStatus);

                lstNotifications.add(new NotificationModel(notificationID, lawID, notificationType, notificationText, notificationTime, notificationStatus));
            } catch (Exception e) {
                exceptionHandler.alert(e, "getNotificationList()");
            }
            cursor.moveToNext();
        }
    }
    close();
    Collections.reverse(lstNotifications);
    return lstNotifications;
}

}

主要活動:

sqLiteAdapter.updateLaw(962, "test", "test");

您在此代碼中很難檢測到您所描述的問題,但這里列出了您應該考慮的注釋/最佳實踐:

  • 您應該始終在輔助線程上而不是在主線程上執行數據庫查詢(嘗試AsyncTask)。
  • 你有一個SimpleGestureFilter,我不能說它是什么或它做什么。 如果你有一些丑陋的邏輯,那可能會影響滾動。
  • 你在getView()方法中創建了大量的LayoutInflater變量,這非常糟糕。 使其成為全局變量並在Adapter的構造函數中初始化它。 你知道滾動時調用getView()方法的次數嗎? 把日志放在那里分析:)。
  • 絕對不能在適配器中保存SQLiteAdapter對象的實例。 在您的活動中執行此操作並在需要時更新適配器。 適配器應該始終是數據的表示,而不是邏輯和其他任何東西。
  • 不確定FontLoader的作用但是如果每次調用getView()時從資源中讀取字體,就會出現huuuge問題。 嘗試盡可能少地加載字體,因為這是一個繁重的操作。
  • 永遠不要抓住一般例外。 盡量專注於具體的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM