属性里面不能有this
来源:互联网 发布:番茄 软件 编辑:程序博客网 时间:2024/04/25 19:18
可以放到构造器或是onCreate()中
package com.example.cpa;import android.content.ContentResolver;import android.content.ContentValues;import android.net.Uri;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Toast;public class MainActivity extends AppCompatActivity { public static final String URI_STR="content://com.wy.cpb"; public static final Uri URI_CP=Uri.parse(URI_STR);// ContentResolver mContentResolver= this.getContentResolver();//这样不对,要放到构造器中 ContentResolver mContentResolver; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContentResolver= this.getContentResolver(); } public void go1(View view) { Toast.makeText(this, "增加数据", Toast.LENGTH_SHORT).show(); ContentValues mContentValues=new ContentValues(); mContentValues.put("username","wy"); mContentValues.put("sex","boy"); mContentResolver.insert(URI_CP,mContentValues);// ContentValues contentValues=new ContentValues();// contentValues.put("username","erhuang999");// contentValues.put("sex","母");// Uri insert = contentResolver.insert(URI_CP, contentValues);// long id= ContentUris.parseId(insert);// Toast.makeText(this, insert.toString()+ " id值为:" + id, Toast.LENGTH_SHORT).show(); }// public void go2(View view) {//// Toast.makeText(this, "查询全部数据", Toast.LENGTH_SHORT).show();//// Cursor cursor = contentResolver.query(URI_CP, new String[]{"username", "sex"}, "sex=?", new String[]{"man"}, null);//// StringBuilder stringBuilder=new StringBuilder();//// while (cursor.moveToNext()){//// stringBuilder.append(cursor.getString(cursor.getColumnIndex("username")));//// stringBuilder.append("\t");//// stringBuilder.append(cursor.getString(cursor.getColumnIndex("sex")));//// stringBuilder.append("\r\n");//// }//// cursor.close();//// tv.setText(stringBuilder.toString());//// //content://com.sj.cp/mycpall// String uriStr=URI_STR+"/mycpall";// Uri uri = Uri.parse(uriStr);// contentResolver.query(uri,null,null,null,null);// }//// public void go3(View view) {// Toast.makeText(this, "查询指定ID数据", Toast.LENGTH_SHORT).show();//// //content://com.sj.cp/mycp/3// String uriStr=URI_STR+"/mycp/3";// Uri uri = Uri.parse(uriStr);// contentResolver.query(uri,null,null,null,null);//// }//// public void go4(View view) {// Toast.makeText(this, "删除数据", Toast.LENGTH_SHORT).show();// contentResolver.delete(URI_CP,"username=?",new String[]{"dahuang2"});//// }//// public void go5(View view) {// Toast.makeText(this, "修改数据", Toast.LENGTH_SHORT).show();// ContentValues contentValues=new ContentValues();// contentValues.put("username","erhuang6666");// contentResolver.update(URI_CP,contentValues,"username=?",new String[]{"dahuang6"});// }}
0 0
- 属性里面不能有this
- Static 方法里面为何不能使用this
- jQuery里面用this和用$(this)有什么区别?
- ANT_HOME和JAVA_HOME里面不能有';'
- jquery 获取 id ,但是id 里面不能有. 这个符号
- jquery里面的$(this)和this都什么时候用,有什么区别
- jquery里面的$(this)和this都什么时候用,有什么区别
- jquery里面的$(this)和this都什么时候用,有什么区别
- switch case语句里面不能定义对象 错误信息:Cannot jump from switch statement to this case..
- 类的成员变量有一个隐含的参数this,所以必须保存这个this 到MemberFunctionSlot 类里面
- c#里面 : this()是什么意思?
- Jquery里面的this
- js 里面的this
- switch case语句里面不能定义对象,有语法错误,除非加一个花括号
- switch case语句里面不能定义对象,有语法错误,除非加一个花括号
- ListView里面有EditTextView,解决弹出键盘后EditView不能获取焦点的问题
- switch case语句里面不能定义对象,有语法错误,除非加一个花括号
- iOS中switch case语句里面不能定义对象,有语法错误,除非加一个花括号
- 51nod 1352 集合计数
- 百度地图Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.baidu.map
- hdu1573Drainage Ditches
- jquery 如何判断是否已经fadein/fadeout? 判断是否隐藏hide()/show()
- 51nod 1381 硬币游戏
- 属性里面不能有this
- 51nod 1384 全排列
- Field 'id' doesn't have a default value 原因
- CAN总线
- 51nod 1391 01串
- Apache zookeeper 小试牛刀
- 51nod 1393 0和1相等串
- window10 系统查看控制面板的方法
- FragmentPagerAdapter与FragmentStatePagerAdapter区别