我在我的应用程序中有这个简单的计时器,每3秒运行一次.如果它不在片段类中,它可以完美地工作.但是在片段中我总是得到错误:只有创建视图层次结构的原始线程才能触及其视图.
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
String timeStamp = new SimpleDateFormat(
"yyyy.MM.dd HH:mm:ss").format(Calendar
.getInstance().getTime());
System.out.println("TimeStamp: " + timeStamp);
// Read And Write Register Sample
port = Integer.parseInt(gConstants.port);
String refe = "0";// HEX Address
ref = Integer.parseInt(refe, 16);// Hex to int
count = 10; // the number Address to read
SlaveAddr = 1;
astr = gConstants.ip; // Modbus Device
InetAddress addr;
try {
addr = InetAddress.getByName(astr);
con = new TCPMasterConnection(addr); // the
// connection …Run Code Online (Sandbox Code Playgroud) 有没有解决方法如何选择保存文件位置?也许用原始文件浏览器,选择目的地?
谢谢!
是否可以使用MPAndroidChart(或任何其他Android图表库)以渐变颜色填充绘制线下的图表?像这样的东西:
set1.setFillColor(getResources().getColor(R.drawable.chart_fill));
Run Code Online (Sandbox Code Playgroud)
然后在chart_fill.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#FF207a54"
android:startColor="#FFffffff" />
</shape>
Run Code Online (Sandbox Code Playgroud) 我有这个小gps locaton插入代码但不插入数据库:
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String gps = "CREATE TABLE IF NOT EXISTS GPS_Values ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, Latitude float(10, 6), Longitude float(10, 6), cur_timestamp TIMESTAMP);";
db.execSQL(gps);
Run Code Online (Sandbox Code Playgroud)
和插入行:
// GPS
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
ContentValues gps_values = new ContentValues();
gps_values.put("Latitude", loc.getLatitude());
gps_values.put("Longitutde", loc.getLongitude());
try {
db.beginTransaction();
db.insert("GPS_Values", null, gps_values);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
String Text = "My current location is: " + "Latitude = " …Run Code Online (Sandbox Code Playgroud) 我在android中有这个数据库打印机.

Cursor curTAB = myDataBase.rawQuery("SELECT * FROM GPS_Values;", null);
Integer count = 0;
while (curTAB.moveToNext()) {
String s_latitude = curTAB.getString(1);
String s_longitude = curTAB.getString(2);
String s_speed = curTAB.getString(5);
count++;
String next_speed = ???
}
curTAB.close();
myDataBase.close();
Run Code Online (Sandbox Code Playgroud)
我想知道如何在循环中获得下一个速度?