Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

After your successful build of the Main activity, you will need to change its in

ID: 3703843 • Letter: A

Question

After your successful build of the Main activity, you will need to change its inheritance from an Activity to a ListActivity and drag a ListView container into the RelativeLayout of the MainActivity. This Activity will be used to list all of the categories and will use a secondary layout that contains the Layout Definition (id and category). The easiest way to load the categories is by using an arrays.xml to load the SQL table – you can run the load the first time you create the database and only reload the category table if you have to recreate your SQL tables. To load the ListView, you would use a SimpleCursorAdapter and point to the secondary layout to load the fields for id and category. Use an intent to open a second Title ListViewActivity only based on setOnItemClickListener for the CursorAdapter. Be sure to use the intent.putextra to pass the selected category to the Title ListViewActivity.

my code so far

Explanation / Answer

Hi,
1. MainActivity.java

2. activity_main.xml

3. ListViewActivity.java

4. activity_main2.xml

5.

6.MyDBHandler.java

package com.myapp;

import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import static android.content.ContentValues.TAG;

public class MyDBHandler extends SQLiteOpenHelper {

private final Context fContext;
static String title;
MyDBHandler(Context context) {
super(context, "sampledb", null, 1);
fContext = context;
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE mytable ("
+ "_id INTEGER PRIMARY KEY,"
+ "title TEXT"
+ ");");


ContentValues _Values = new ContentValues();

Resources res = fContext.getResources();
String[] _mytable_Records = res.getStringArray(R.array.mytable_records_v1);

int _Length = _mytable_Records .length;
for (int i = 0; i < _Length; i++) {
_Values.put("title", _mytable_Records [i]);
db.insert("mytable", null, _Values);
}
}

public Cursor GetAllData()
{
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery("SELECT * FROM mytable;", null);
return c;
}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS _mytable_Records ");
onCreate(db);
}
}

7.row_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Please use this updated

Let me know if any change required..

Thank you!