Created
December 11, 2014 20:34
-
-
Save azec-pdx/4a0a1feb9c3cfe38f931 to your computer and use it in GitHub Desktop.
UI za ContentProviderExample
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
public void onClickAddName(View view){ | |
//Dodaj novi studentski rekord | |
ContentValues values = new ContentValues(); | |
values.put(StudentProvider.NAME, | |
((EditText)findViewById(R.id.txtName)).getText().toString()); | |
values.put(StudentProvider.GRADE, | |
((EditText)findViewById(R.id.txtGrade)).getText().toString()); | |
Uri uri = getContentResolver().insert(StudentProvider.CONTENT_URI, values); | |
Toast.makeText(getBaseContext(), | |
uri.toString(), Toast.LENGTH_LONG).show(); | |
} | |
public void onClickRetrieveStudents(View view) { | |
//Retrueve student records | |
String URL = "content://ba.edu.eksa.Fakultet/studenti"; | |
Uri students = Uri.parse(URL); | |
String[] projection = | |
{ | |
StudentProvider._ID, | |
StudentProvider.NAME, | |
StudentProvider.GRADE | |
}; | |
String sortOrder = StudentProvider.NAME; | |
Cursor c = getApplicationContext().getContentResolver().query(students, projection, null, null, sortOrder); | |
if (c.moveToFirst()) { | |
do { | |
Toast.makeText(this, | |
c.getString(c.getColumnIndex(StudentProvider._ID)) + | |
", " + c.getString(c.getColumnIndex(StudentProvider.NAME)) + | |
", " + c.getString(c.getColumnIndex(StudentProvider.GRADE)), | |
Toast.LENGTH_SHORT).show(); | |
} while (c.moveToNext()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment