SoFunction
Updated on 2025-04-10

Android Development Notes: Detailed explanation of the problem of ListView refresh order


public class ListOrderActivity extends Activity {
    private ListView mTaskList;
    private EditText mAddTaskEditor;
    private LayoutInflater mFactory;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.list_activity);

        mFactory = (getApplication());
        mTaskList = (ListView) findViewById(.task_list);
        final View headerView = (.header_view, null);
        (headerView);
        mAddTaskEditor = (EditText) (.task_editor);
        (new OnKeyListener() {
            @Override
            public boolean onKey(View view, int keycode, KeyEvent event) {
         if (keycode == KeyEvent.KEYCODE_DPAD_CENTER || keycode == KeyEvent.KEYCODE_ENTER) {
             // finish editing
             final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
             (getCurrentFocus().getWindowToken(), 0);
             final String text = ().toString();
             if (!(text)) {
          final ContentValues values = new ContentValues(1);
          (, text);
          (, Task.TYPE_TODAY);
          getContentResolver().insert(Task.CONTENT_URI, values);
             }
             ("");
         }
         return false;
            }
        });
        final Cursor cursor = getContentResolver().query(Task.CONTENT_URI, , + " = " + Task.TYPE_TODAY, null, null);
        final TaskAdapter adapter = new TaskAdapter(getApplication(), cursor);
        (adapter);
    }

    private class TaskAdapter extends CursorAdapter {
        private Cursor mCursor;

        public TaskAdapter(Context context, Cursor c) {
            super(context, c);
            mCursor = c;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            if (view  == null) {
                view = (.today_task_item, null);
            }
            final ViewSwitcher switcher = (ViewSwitcher) (.action_switcher);
//            if (() == 1) {
//         ();
//         ();
//         ();
//            }
            final CheckBox toggle = (CheckBox) (.action_toggle_done);
            final short done = ();
            final int id = ();
            (null);
            (done != 0);
            (new OnCheckedChangeListener() {
         @Override
         public void onCheckedChanged(CompoundButton view, boolean checked) {
             final Uri uri = (Task.CONTENT_URI, id);
             final ContentValues values = new ContentValues(1);
             (, checked ? 1 : 0);
             getContentResolver().update(uri, values, null, null);
         }
            });
            (new OnClickListener() {
         @Override
         public void onClick(View v) {
             ();
             if (() == 0) {
          ().setAnimationListener(null);
          return;
             }
             final ImageView delete = (ImageView) (.action_delete_task);
             (new OnClickListener() {
          @Override
          public void onClick(View v) {
              ().setAnimationListener(new AnimationListener() {
           @Override
           public void onAnimationEnd(Animation animation) {
               ().setAnimationListener(null);
               final Uri uri = (Task.CONTENT_URI, id);
               getContentResolver().delete(uri, null, null);
           }

           @Override
           public void onAnimationRepeat(Animation animation) {
           }

           @Override
           public void onAnimationStart(Animation animation) {
           }
              });
              ();
          }
      });
         }
     });
            TextView task = (TextView) ();
            final String taskContent = ();
            if (done != 0) {
         final Spannable style = new SpannableString(taskContent);
         (new StrikethroughSpan(), 0, (), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
         (new StyleSpan() , 0, (), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
         (style);
         (getApplication(), .done_task_item_text);
            } else {
         (taskContent);
         (getApplication(), .task_item_text);
            }
        }
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            View view = (.today_task_item, null);
            return view;
        }

        @Override
        public void onContentChanged() {
            ();
        }
    }
}