Mi salvo il codice:
public class MainActivity extends AppCompatActivity {
Helper helper;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
helper=new Helper(this);
/*helper.save("Mario");
helper.save("Pasquale");*/
helper.saveData(1,"Primo");
}
class Helper extends SQLiteOpenHelper{
public Helper(Context context) {
super(context, "mioDatabase.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table tblNomi(_id integer primary key, nome text)");
db.execSQL("create table tblDati(_id integer primary key, extKey integer, dato text)");
}
public void save(String nome){
SQLiteDatabase db=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("nome",nome);
db.insert("tblNomi",null,values);
}
public void saveData(int id, String dato){
SQLiteDatabase db=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("extKey",id);
values.put("dato",dato);
db.insert("tblDati",null,values);
}
public Cursor query(int id){
SQLiteDatabase db=this.getWritableDatabase();
Cursor c=db.rawQuery("select * from tblNomi where _id="+id, null);
c.moveToFirst();
return c;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/imageView"
android:layout_weight="1" />
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"/>
</LinearLayout>
Nessun commento:
Posta un commento