Android development today reported errors and Solutions

I wrote a few files of registration and login functions in another project. There was a problem when I wanted to combine these codes with another file.

First, you can't directly copy a file from another project,

The best way is to create a new file with the same name, and then copy the code in another file (do not copy except the package name).

Then all activity files should be registered in the androidmanifest file

Add public void add (string username, string useraddress){

    db.execsql("INSERT INTO user (username,?)"
  ,new Object[]{username,useraddress});

}
查询方法
public ArrayList<User> getAllData()
ArrayList<User> list = new ArrayList<User>(); Cursor cursor = db.query("user","username DESC" while(cursor.moveToNext()){ String username = cursor.getString(cursor.getColumnIndex("username"));

        String userid = cursor.getString(cursor.getColumnIndex("userid"));
String userphone = cursor.getString(cursor.getColumnIndex("userphone"));
String useraddress = cursor.getString(cursor.getColumnIndex("useraddress"));
list.add(new User(username,useraddress));
}
Log.v("输出数据库查询结果:",list.toString());
return list;
}
1、close()  关闭游标,释放资源
2、getColumnCount()返回所有列的总数
3、getColumnIndexOrThrow(String columnName)
  从零开始返回指定列名称,如果不存在将抛出IllegalArgumentException 异常。
4、moveToNext()    
  移动光标到下一行
5、moveToFirst()
  移动光标到第一行
6、moveToPosition(int position)
移动光标到一个绝对的位置
7、moveToPrevIoUs() 移动光标到上一行

数据库构造函数

public DBOpenHelper(Context context){
super(context,1);
db = getReadableDatabase();
}

onCreate()方法

public void onCreate(sqliteDatabase db){
db.execsql("CREATE TABLE IF NOT EXISTS user(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"username TEXT," +
"userid TEXT,"+
"userphone TEXT,"+
"useraddress TEXT)"
);
}
注意不要丢掉_id 主键
每一段定义后面都有一个英文的逗号、

Intent intent2 = new Intent(this,MainActivity.class);
startActivity(intent2);

自动获取时间

public void autoTimeAndDate(View view)
{
text2=(EditText)findViewById(R.id.tv_text2);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
//获取当前时间
Date date = new Date(System.currentTimeMillis());
text2.setText(simpleDateFormat.format(date));
}

//获取当前地址

所以大概是这样的
LocationClient这个类定义的是用户使用的类
MyLocationLisenter 这个类定义一个监听的工具,BDLocation这个类用来获取具体的地址字符串

mLocationClient.registerLocationListener(myListener);  这句话就是把用户的类和监听类绑定在一起

28-30行的内容用户对这个地图的选项设置

LocationClientOption lcOption = new LocationClientOption();

//Setting the positioning mode: high precision, low power consumption, only the device lcoption.setlocationmode (locationmode. High t_accuracy)// Set the coordinate system lcoption.setcoortype ("bd09ll")// Set GPS to open lcoption.setopengps (true)// Set the required address information lcoption. Setisneedaddress (true)// Set lcoption.setscanspan (1000) to update location information every second// Set lcoption.setisneedlocationdescribe (true) where location description information is required;

mBdLocationManager.setLocOption(lcOption); ———————————————— Copyright notice: This is the original article of CSDN blogger "autumn should be good", which follows the CC 4.0 by-sa copyright agreement. Please attach the original source link and this notice for reprint. Original link: https://blog.csdn.net/qq_ 36444585/article/details/78152765

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>