class="article_content clearfix">
class="htmledit_views">
contentprovider_provider的MainActivity什么也不写
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs java has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">
android.support.v7.app.AppCompatActivity;
android.os.Bundle;
(Bundle savedInstanceState) {
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
MyContentProvider
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs java has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">class="tags" href="/tags/PATH.html" title=path>path = ;
SQLiteDatabase db;
() {
MySQliteopenHelper openher = MySQliteopenHelper(getContext());
db = openher.getReadableDatabase();
;
}
Cursor (Uri uri, String[] class="tags" href="/tags/STRING.html" title=string>strings, String s, String[] class="tags" href="/tags/STRING.html" title=string>strings1, String s1) {
Cursor c = db.query( ,class="tags" href="/tags/STRING.html" title=string>strings,s,class="tags" href="/tags/STRING.html" title=string>strings1, , ,s1);
c;
}
String (Uri uri) {
;
}
Uri (Uri uri, ContentValues contentValues) {
insert = db.insert( , , contentValues);
Uri u = ContentUris.withAppendedId(Uri.parse(class="tags" href="/tags/PATH.html" title=path>path),insert);
u;
}
(Uri uri, String s, String[] class="tags" href="/tags/STRING.html" title=string>strings) {
;
}
(Uri uri, ContentValues contentValues, String s, String[] class="tags" href="/tags/STRING.html" title=string>strings) {
;
}
}
android.content.ContentProvider;
android.content.ContentUris;
android.content.ContentValues;
android.database.Cursor;
android.database.sqlite.SQLiteDatabase;
android.net.Uri;
android.support.annotation.Nullable;
String
MySQliteopenHelper
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs java has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">
android.content.Context;
android.database.sqlite.SQLiteDatabase;
android.database.sqlite.SQLiteOpenHelper;
(Context context) {
(context, , , );
}
(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL( );
}
(SQLiteDatabase sqLiteDatabase, i, i1) {
}
}
activity_main的布局
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs perl has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal"><RelativeLayout
xmlns:android=
xmlns:tools=
android:layout_width=
android:layout_height=
android:paddingBottom=
android:paddingLeft=
android:paddingRight=
android:paddingTop=
tools:context= >
<TextView
android:layout_width=
android:layout_height=
android:text= />
<
contentprovider_resolver的MainActivity
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs java has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">class="tags" href="/tags/PATH.html" title=path>path = ;
Button query_bt;
Button insert_bt;
Button delete_bt;
ListView listView;
ContentResolver mResolver;
(Bundle savedInstanceState) {
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mResolver = getContentResolver();
initView();
}
() {
query_bt = (Button) findViewById(R.id.query_bt);
insert_bt = (Button) findViewById(R.id.insert_bt);
delete_bt = (Button) findViewById(R.id.delete_bt);
listView = (ListView) findViewById(R.id.listView);
query_bt.setOnClickListener( );
insert_bt.setOnClickListener( );
delete_bt.setOnClickListener( );
}
(View v) {
(v.getId()) {
R.id.query_bt:
queryStudent();
;
R.id.insert_bt:
insertStudent();
;
R.id.delete_bt:
;
}
}
() {
View dialogView = View.inflate( , R.layout.dialog_layout, );
EditText name_et = (EditText) dialogView.findViewById(R.id.name_et);
EditText age_et = (EditText) dialogView.findViewById(R.id.age_et);
AlertDialog.Builder builder = AlertDialog.Builder( );
builder.setIcon(R.mipmap.ic_launcher).setTitle( ).setMessage( ).setView(dialogView)
.setPositiveButton( , DialogInterface.OnClickListener() {
(DialogInterface dialog, which) {
String name = name_et.getText().toString();
String age = age_et.getText().toString();
ContentValues values = ContentValues();
values.put( , name);
values.put( , age);
mResolver.insert(Uri.parse(class="tags" href="/tags/PATH.html" title=path>path), values);
}
});
builder.show();
}
() {
Cursor c = mResolver.query(Uri.parse(class="tags" href="/tags/PATH.html" title=path>path), , , , );
ArrayList<Student> list = ArrayList<Student>();
(c != ) {
(c.moveToNext()) {
String name = c.getString(c.getColumnIndex( ));
String age = c.getString(c.getColumnIndex( ));
Student stu = Student(name,age);
list.add(stu);
}
}
listView.setAdapter( StudentAdapter( , list));
}
}
android.content.ContentResolver;
android.content.ContentValues;
android.content.DialogInterface;
android.database.Cursor;
android.net.Uri;
android.os.Bundle;
android.support.v7.app.AlertDialog;
android.support.v7.app.AppCompatActivity;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.ListView;
java.util.ArrayList;
String
Student
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs cs has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">
Student {
String name;
String age;
String () {
name;
}
(String name) {
.name = name;
}
String () {
age;
}
(String age) {
.age = age;
}
() {
}
(String name, String age) {
.name = name;
.age = age;
}
}
StudentAdapter
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs java has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">class ViewHolder{
TextView name_tv,age_tv;
}
}
android.content.Context;
android.view.LayoutInflater;
android.view.View;
android.view.ViewGroup;
android.widget.BaseAdapter;
android.widget.TextView;
java.util.ArrayList;
Context mContext;
ArrayList<Student> mList;
LayoutInflater mInflater;
(Context context, ArrayList<Student> list) {
mContext = context;
mList = list;
mInflater = LayoutInflater.from(mContext);
}
() {
(mList!= ){
mList.size();
}
;
}
Student ( i) {
(mList!= ){
mList.get(i);
}
;
}
( i) {
i;
}
View ( i, View view, ViewGroup viewGroup) {
ViewHolder vh = ;
(view == ){
vh = ViewHolder();
view = mInflater.inflate(R.layout.item_layout, );
vh.name_tv = (TextView) view.findViewById(R.id.name_tv);
vh.age_tv = (TextView) view.findViewById(R.id.age_tv);
view.setTag(vh);
} {
vh = (ViewHolder) view.getTag();
}
Student student = getItem(i);
vh.name_tv.setText(student.getName());
vh.age_tv.setText(student.getAge());
view;
}
StudentAdapter
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs java has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">class ViewHolder{
TextView name_tv,age_tv;
}
}
android.content.Context;
android.view.LayoutInflater;
android.view.View;
android.view.ViewGroup;
android.widget.BaseAdapter;
android.widget.TextView;
java.util.ArrayList;
Context mContext;
ArrayList<Student> mList;
LayoutInflater mInflater;
(Context context, ArrayList<Student> list) {
mContext = context;
mList = list;
mInflater = LayoutInflater.from(mContext);
}
() {
(mList!= ){
mList.size();
}
;
}
Student ( i) {
(mList!= ){
mList.get(i);
}
;
}
( i) {
i;
}
View ( i, View view, ViewGroup viewGroup) {
ViewHolder vh = ;
(view == ){
vh = ViewHolder();
view = mInflater.inflate(R.layout.item_layout, );
vh.name_tv = (TextView) view.findViewById(R.id.name_tv);
vh.age_tv = (TextView) view.findViewById(R.id.age_tv);
view.setTag(vh);
} {
vh = (ViewHolder) view.getTag();
}
Student student = getItem(i);
vh.name_tv.setText(student.getName());
vh.age_tv.setText(student.getAge());
view;
}
activity_main布局
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs xml has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">
dialog_layout
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs xml has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">
item_layout
class="prettyprint" style="font-family:"Source Code Pro",monospace; font-size:14px; white-space:nowrap; padding:5px 5px 5px 60px; margin-top:0px; margin-bottom:1.1em; line-height:1.45; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; position:relative; overflow-y:hidden; overflow-x:auto">class="hljs xml has-numbering" style="font-family:"Source Code Pro",monospace; font-size:undefined; padding:0px; color:inherit; white-space:pre; background:transparent; display:block; word-wrap:normal">