This video exhibits the steps to create a SQLite database from scratch. Then it exhibits how one can write (Insert or replace) the information within the database. Additional, it exhibits the code to question the database and fetch the required information from the database. Lastly, it exhibits how you can use the fetched information to show it on a textual content view within the App’s structure and likewise to create a PDF file to write down that textual content within the PDF.
We hope you want this video. For any question, strategies or appreciations we might be glad to listen to from you at: programmerworld1990@gmail.com or go to us at: https://programmerworld.co
Supply Code at:
https://programmerworld.co/android/how-to-fetch-data-from-sqlite-database-and-put-that-in-a-pdf-file-in-your-android-app-source-code/
bundle com.instance.mysqlitedbtopdffile;
import android.content material.ContentValues;
import android.content material.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Paint;
import android.graphics.pdf.PdfDocument;
import android.os.Bundle;
import android.os.Atmosphere;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class MainActivity extends AppCompatActivity {
personal mySQLiteDBHandler sqlLiteDBHandler;
personal EditText editTextSerialNumberInsert;
personal EditText editTextSerialNumberFetch;
personal EditText editTextInsert;
personal TextView textViewDisplay;
personal SQLiteDatabase sqLiteDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
tremendous.onCreate(savedInstanceState);
setContentView(R.structure.activity_main);
ActivityCompat.requestPermissions(this,new String[]{READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
attempt {
sqlLiteDBHandler = new mySQLiteDBHandler(this,”PDFDatabase”, null,1);
sqLiteDatabase = sqlLiteDBHandler.getWritableDatabase();
sqLiteDatabase.execSQL(“CREATE TABLE PDFTable(SerialNumber TEXT, Textual content TEXT)”);
}
catch (Exception e){
e.printStackTrace();
}
editTextInsert = findViewById(R.id.editText2);
editTextSerialNumberInsert = findViewById(R.id.editText);
editTextSerialNumberFetch = findViewById(R.id.editText3);
textViewDisplay = findViewById(R.id.textView);
}
public void InsertUpdatedButton(View view){
ContentValues contentValues = new ContentValues();
contentValues.put(“SerialNumber”, editTextSerialNumberInsert.getText().toString());
contentValues.put(“Textual content”, editTextInsert.getText().toString());
sqLiteDatabase.insert(“PDFTable”,null,contentValues);
sqLiteDatabase.replace(“PDFTable”, contentValues, null,null);
}
public void CreatePDF(View view){
String question = “Choose Textual content from PDFTable the place SerialNumber=” + editTextSerialNumberFetch.getText().toString();
Cursor cursor = sqLiteDatabase.rawQuery(question,null);
attempt {
cursor.moveToFirst();
textViewDisplay.setText(cursor.getString(0));
}
catch (Exception e){
e.printStackTrace();
textViewDisplay.setText(“”);
return;
}
PdfDocument pdfDocument = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(300, 600,1).create();
PdfDocument.Web page web page = pdfDocument.startPage(pageInfo);
web page.getCanvas().drawText(cursor.getString(0),10, 25, new Paint());
pdfDocument.finishPage(web page);
String filePath = Atmosphere.getExternalStorageDirectory().getPath()+”/Obtain/”+editTextSerialNumberFetch.getText().toString()+”.pdf”;
File file = new File(filePath);
attempt {
pdfDocument.writeTo(new FileOutputStream(file));
} catch (IOException e) {
e.printStackTrace();
}
pdfDocument.shut();
}
}
————–
bundle com.instance.mysqlitedbtopdffile;
import android.content material.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class mySQLiteDBHandler extends SQLiteOpenHelper {
public mySQLiteDBHandler(@Nullable Context context, @Nullable String title, @Nullable SQLiteDatabase.CursorFactory manufacturing facility, int model) {
tremendous(context, title, manufacturing facility, model);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
source
Sacramento's premier marketing agencies deliver top-quality service at a highly competitive rate. They tailor strategies…
IAAI provides various services that enable buyers and sellers to acquire or dispose of vehicles…
Cyprusnews is an online news site that provides up-to-the-minute protection and is committed to self-reliance,…
Executive CV writing services specialize in crafting well-written documents that attract recruiters' interest. They also…
Introduction: Overview of Becoming a Commercial Pilot Becoming a commercial pilot is not just about…
Beginners looking to start trading forex should choose a platform with plenty of educational materials,…