1

What im trying to do is change the value of 1 edittext in each listItem. i.e the DueDate is coming from database as a dateString 01/01/2016 and i want to change it to how many days are between now and then instead when it appears in the listView.

I need to get the value its set to now and send it through a method to calculate the days between now and then which is easy enough but the problem is when using a cursorAdapter theres no loop that i can edit the edittext.

getValues Method which fills the list

final String[] from = new String[]{"_id", "ProjectSubject", "ProjectTitle", "ProjectWorth", "ProjectDueDate", "ProjectDetails"};
    final int[] to = new int[]{R.id.IdText, R.id.SubjectTextList, R.id.ProjectTitleTextList, R.id.WorthText, R.id.DueDateTextList, R.id.DetailsTextList};

    Cursor cursor = dbHelper.fetchAllProjects();
    dataAdapter = new SimpleCursorAdapter(context, R.layout.summary_list_item,cursor,from, to, 0);

    list.setAdapter(dataAdapter);

Adapter method which fetches the projects

 public Cursor fetchAllProjects() {

    Cursor mCursor = mDb.query(SQLITE_TABLE, new String[]{
                    KEY_ID,
                    KEY_SUBJECT,
                    KEY_TYPE,
                    KEY_TITLE,
                    KEY_WORTH,
                    KEY_DUEDATE,
                    KEY_DETAILS,
                    KEY_EMAIL},
            null, null, null, null, null, null);

    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;



}

Edit -

dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
                                  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                                      if (columnIndex == 5) {
                                          ((TextView) dueDateText).setText(cursor.getString(columnIndex) + " modified");
                                          return true;
                                      } else {
                                          return false;
                                      }
                                  }
                              });

1 Answer 1

1

You should use ViewBinder

e.g.

dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
        if(columIndex==3) {
             ((TextView)view).setText(cursor.getString(columnIndex)+" modified");
             return true;
        } else {
             return false;
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks i still think im wrong. Ive edited the original text. Im getting Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference which is pointing to dueDateText
sorry, I have made a typo before, for your code, replace dueDateText with view
Great. Thanks. Im fairly certain i can get it from here. Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.