Example usage for android.widget CursorAdapter CursorAdapter

List of usage examples for android.widget CursorAdapter CursorAdapter

Introduction

In this page you can find the example usage for android.widget CursorAdapter CursorAdapter.

Prototype

@Deprecated
public CursorAdapter(Context context, Cursor c) 

Source Link

Document

Constructor that always enables auto-requery.

Usage

From source file:br.com.anteros.android.persistence.backup.DatabaseMaintenanceFragment.java

@Nullable
@Override/*from w  w  w .ja v  a 2  s . c  o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.databasemaintenance, null);

    lvTables = (ListView) view.findViewById(R.id.listview_database);
    try {
        connection = (SQLiteConnection) getSQLSession().getConnection();
    } catch (Exception e) {
    }
    cursor = connection.getDatabase()
            .rawQuery("SELECT name as _id FROM sqlite_master WHERE type='table' ORDER BY name;", null);

    adapter = new CursorAdapter(getActivity(), cursor) {

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            LayoutInflater inflater = LayoutInflater.from(context);
            View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
            bindView(view, context, cursor);
            return view;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            TextView lbTabela = (TextView) view.findViewById(android.R.id.text1);
            try {
                lbTabela.setText(getObjectValue(cursor, 0) + "");
            } catch (SQLException e) {
                e.printStackTrace();
                lbTabela.setText("");
            }
        }

    };

    lvTables.setAdapter(adapter);
    lvTables.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
            String table = "";

            try {
                table = getObjectValue((Cursor) adapter.getItem(position), 0) + "";
            } catch (SQLException e) {
                e.printStackTrace();
            }

            RecordsOfTableActivity.setData(table, getSQLSession());

            startActivity(new Intent(getActivity(), RecordsOfTableActivity.class));

            return false;
        }
    });

    return view;
}