Answer the question
In order to leave comments, you need to log in
Guys, I can't fill the ListView with data from the database, is the problem in SimpleCursorAdapter?
I'm trying to fill the ListView with data from the database, but something goes wrong... Help me figure out what the problem is))
Code:
package com.example.restaurantmenu;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class DrinkActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
setContentView(R.layout.activity_drink);
SQLiteOpenHelper rDatabaseHelper = new RestaurantDatabaseHelper(this);
SQLiteDatabase db = rDatabaseHelper.getWritableDatabase();
Cursor cursor = db.query("DB", new String[]{"_id", "NAME"}, null, null, null, null, null);
CursorAdapter scAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1, cursor,new String []{"NAME"}, new int[]{android.R.id.text1},0);
ListView listView = (ListView) findViewById(R.id.listViewDrink);
listView.setAdapter(scAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(DrinkActivity.this,DrinkItem.class);
intent.putExtra(DrinkItem.EXTRA_DRINKNO2,(int)id);
startActivity(intent);
}
}
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question