-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e9dae1
commit 10993b1
Showing
8 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/dev/ujjwal/sqlitedatastorage/ShowActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.ujjwal.sqlitedatastorage; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.database.Cursor; | ||
import android.os.Bundle; | ||
import android.widget.ListView; | ||
|
||
import dev.ujjwal.sqlitedatastorage.data.StudentContract.StudentEntry; | ||
|
||
public class ShowActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_show); | ||
|
||
String[] projection = {StudentEntry._ID, | ||
StudentEntry.COLUMN_QR_CODE_ID, | ||
StudentEntry.COLUMN_NAME, | ||
StudentEntry.COLUMN_BATCH}; | ||
Cursor cursor = getContentResolver().query( | ||
StudentEntry.CONTENT_URI, | ||
projection, | ||
null, | ||
null, | ||
null); | ||
|
||
ListView listView = findViewById(R.id.activity_show_listView); | ||
StudentCursorAdapter studentCursorAdapter = new StudentCursorAdapter(this, cursor); | ||
listView.setAdapter(studentCursorAdapter); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/dev/ujjwal/sqlitedatastorage/StudentCursorAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dev.ujjwal.sqlitedatastorage; | ||
|
||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.CursorAdapter; | ||
import android.widget.TextView; | ||
|
||
import dev.ujjwal.sqlitedatastorage.data.StudentContract.StudentEntry; | ||
|
||
public class StudentCursorAdapter extends CursorAdapter { | ||
|
||
public StudentCursorAdapter(Context context, Cursor c) { | ||
super(context, c, 0); | ||
} | ||
|
||
@Override | ||
public View newView(Context context, Cursor cursor, ViewGroup parent) { | ||
return LayoutInflater.from(context).inflate(R.layout.item_show, parent, false); | ||
} | ||
|
||
|
||
@Override | ||
public void bindView(View view, Context context, Cursor cursor) { | ||
TextView nameTextView = view.findViewById(R.id.name_item_show); | ||
TextView summaryTextView = view.findViewById(R.id.batch_item_show); | ||
|
||
// Find the columns of pet attributes that we're interested in | ||
int nameColumnIndex = cursor.getColumnIndex(StudentEntry.COLUMN_NAME); | ||
int breedColumnIndex = cursor.getColumnIndex(StudentEntry.COLUMN_BATCH); | ||
|
||
// Read the pet attributes from the Cursor for the current pet | ||
String petName = cursor.getString(nameColumnIndex); | ||
String petBreed = cursor.getString(breedColumnIndex); | ||
|
||
// Update the TextViews with the attributes for the current pet | ||
nameTextView.setText(petName); | ||
summaryTextView.setText(petBreed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ShowActivity"> | ||
|
||
<ListView | ||
android:id="@+id/activity_show_listView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</RelativeLayout> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="5dp"> | ||
|
||
<TextView | ||
android:id="@+id/name_item_show" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:fontFamily="sans-serif-medium" | ||
android:textAppearance="?android:textAppearanceMedium" | ||
android:textColor="#2B3D4D" /> | ||
|
||
<TextView | ||
android:id="@+id/batch_item_show" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:fontFamily="sans-serif" | ||
android:textAppearance="?android:textAppearanceSmall" | ||
android:textColor="#AEB6BD" /> | ||
</LinearLayout> |