set Id from Cursor to TextView - Android Database

Android examples for Database:Cursor

Description

set Id from Cursor to TextView

Demo Code


import android.database.Cursor;
import android.databinding.BindingAdapter;
import android.support.annotation.Nullable;
import android.widget.TextView;

public class Main{
    @BindingAdapter("cursorDataBindingId")
    public static void setId(TextView textView, @Nullable Cursor cursor) {
        if (cursor == null)
            return;

        int columnId = cursor.getColumnIndex("_id");
        textView.setText(String.valueOf(cursor.getInt(columnId)));
    }/*from ww  w  .  j ava  2s. c  o  m*/
    @BindingAdapter("cursorDataBindingText")
    public static void setText(TextView textView, @Nullable Cursor cursor) {
        if (cursor == null)
            return;

        int columnText = cursor.getColumnIndex("text");
        textView.setText(cursor.getString(columnText));
    }
}

Related Tutorials