2016年3月15日Android实习日记
1.解决了ScrollView滑动冲突问题。
2.设置好了“查看详解”与“题目编号”的部分。
3.完成了app启动图片的设置,并在启动的过程中开辟新的线程连接服务器并开启监听数据。
别忘了注册启动Activity,并设置为app启动项。
参考:http://www.iteye.com/problems/62343
http://www.cnblogs.com/mybkn/archive/2012/07/18/2597347.html
4.mCsv.setEnabled(true);设置是否可以触控,mCsv.setClickable(true);设置是否可以点击
5.在线程中执行Toast操作,报 Can't create handler inside thread that has not called Looper.prepare()这个运行时异常。
是由于Toast依赖一个Handler来消息队列,非主线程需要为Toast准备Looper。
参考:http://blog.csdn.net/neo_86/article/details/25830443
6.
/**
* 连接服务器
*/
public void connectServer() {
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
// TODO Auto-generated method stub
NetworkService.getInstance().onInit(mContext);
NetworkService.getInstance().setupConnection();
// 判断连接状态
if (NetworkService.getInstance().getIsConnected()) {
// Toast.makeText(mContext, "连接成功", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(mContext, "服务器连接失败", Toast.LENGTH_LONG).show();
}
Looper.loop();
}
}).start();
}
7.
A. 有两个方法:
1). int i = Integer.parseInt([String]); 或
i = Integer.parseInt([String],[int radix]);
2). int i = Integer.valueOf(my_str).intValue();
注: 字串转成 Double, Float, Long 的方法大同小异.
1.) String s = String.valueOf(i);
2.) String s = Integer.toString(i);
3.) String s = "" + i;
注: Double, Float, Long 转成字串的方法大同小异.
8. String->char->int
/**
* 当选择答案错误时,显示并改变正确选项的颜色
*/
private void setTrueOptionColor() {
// 显示并改变正确选项的颜色
String getTureId = QuestionList.get(QuestionsIndex).getAnswer();
char temp = getTureId.charAt(0);
((RadioButton) radioGroup.getChildAt(temp - 1 - 65))
.setTextColor(getResources().getColor(R.color.exam_true_option));
}
9.在代码里写入一个输入输出流即可。
具体实现如下:
BufferedReader bf= new BufferedReader(new FileReader("file"));
注:其中file替换为文件路径;
bf.readLine();
注:即可实现一行一行读取txt文档。
10.动态插入数据到数据库,免得手动输入。
package com.magicalign.ortholink.database; import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement; /**
* 插入数据到数据库
*
* @CopyRight: MagicAlign.com
* @author Hanshenquan
* @time 2016年3月15日20:09:43
*/
public class WriteToDatabase { private static String[] mQuestion;
private static String[] mAnswera;
private static String[] mAnswerb;
private static String[] mAnswerc;
private static String[] mAnswerd;
private static String[] mAnswere;
private static String[] mAnswerf;
private static String[] mExamExplain;
private static String[] mTrueAnswer;
// 数据库中数据个数,因为我的数据库里有150条记录
private static int mDataNumber = 150; public static void main(String[] args) throws IOException, SQLException {
// TODO Auto-generated method stub WriteToDatabase.initStringArray();
WriteToDatabase.insertIntoDatabase(); } /**
* 写每一个字段数据
*
* @param array
* @param path
* @throws IOException
*/ private static void writeQuestion(String[] str, String path)
throws IOException {
BufferedReader bf = new BufferedReader(new FileReader(path)); str = new String[mDataNumber]; for (int i = 0; i < mDataNumber; i++) {
str[i] = bf.readLine().trim();
}
bf.close();
for (int i = 0; i < mDataNumber; i++) {
System.out.println(str[i]);
}
} /**
* 得到字符串数组
*
* @throws IOException
*
*/
private static void initStringArray() throws IOException { writeQuestion(mQuestion, "D://data/question.txt");
writeQuestion(mAnswera, "D://data/Answera.txt");
writeQuestion(mAnswerb, "D://data/Answerb.txt");
writeQuestion(mAnswerc, "D://data/Answerc.txt");
writeQuestion(mAnswerd, "D://data/Answerd.txt");
writeQuestion(mAnswere, "D://data/Answere.txt");
writeQuestion(mExamExplain, "D://data/ExamExplain.txt");
writeQuestion(mTrueAnswer, "D://data/TrueAnswer.txt"); } /**
* 执行插入数据库操作
*
* @throws SQLException
*/
private static void insertIntoDatabase() throws SQLException {
Connection conn = DBCon.getConnect();
for (int i = 0; i < mDataNumber; i++) {
String sql = "insert into examination values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql,
Statement.RETURN_GENERATED_KEYS);
pst.setInt(1, i + 1);
pst.setInt(2, 1);
pst.setInt(3, 1);
pst.setString(4, mQuestion[i]);
pst.setString(5, mAnswera[i]);
pst.setString(6, mAnswerb[i]);
pst.setString(7, mAnswerc[i]);
pst.setString(8, mAnswerd[i]);
pst.setString(9, mAnswere[i]);
pst.setString(10, "");// f 默认为空
pst.setString(11, "");// g
pst.setString(12, mExamExplain[i]);
pst.setInt(13, 0);// totalnumber
pst.setInt(14, 0);// wrongnumber
pst.setString(15, mTrueAnswer[i]);
pst.setInt(16, 1); pst.executeUpdate();
pst.close();
conn.close(); } } }
2016年3月15日Android实习日记的更多相关文章
- 2016年3月11日Android实习日记
1.明天删除orthodotics_design_animation_content_gif.gif文件.(已完成) 2. 如何检测内存泄露? A: 可以通过一些性能监测分析工具,如 JProfile ...
- 2016年3月10日Android实习日记
待解决问题: *1:内部ScrollView与外部手势事件滑动冲突问题. *2:Linearlayout+View+LinearLayout横向排列,这其中两个LinearLayout内部各有3个竖向 ...
- 2016年3月9日Android实习日记
1. 解决 org.eclipse.swt.SWTException: Graphic is disposed 问题. 参考:http://www.xuebuyuan.com/1896964.html ...
- 2016年3月8日Android实习日记
1.出现fragment后台栈的bug. bug描述:当点击加入后台栈的操作按钮改变指定控件的内容之后,称为A操作:接下来又点击其它没有操作后台栈的按钮来修改原来指定的控件内容,称为B操作.然后点击b ...
- 2016年3月4日Android实习笔记
1.让水平LinearLayout中的两个子元素分别居左和居右 在LinearLayout中有两个子元素,LinearLayout的orientation是horizontal.需要让第一个元素居左, ...
- 2016年3月3日android实习笔记
1: android自定义控件时,通常需要重写父类构造函数.这三个够找函数具体啥时调用? public View (Context context) 是在java代码创建视图的时候被调用,如果是从xm ...
- 2016年3月1日Android实习笔记
1:经查资料,Android中gif动画加载共有两种 1)利用WebView,WebView 主要调用三个方法:LoadUrl.LoadData.LoadDataWithBaseURL 2)主要用的是 ...
- 2016年3月11日Android学习日记
1.调试技巧:当一次调试过后,可以在App重新返回当前的状态,然后再调试,而不用再点击Android studio的Debug按钮. 参考:http://www.2cto.com/kf/201506/ ...
- 2016年12月15日 星期四 --出埃及记 Exodus 21:10
2016年12月15日 星期四 --出埃及记 Exodus 21:10 If he marries another woman, he must not deprive the first one o ...
随机推荐
- eclipse 反编译
Eclipse Class Decompiler安装此插件,可以编译源代码且调试
- zabbix常见报错问题处理
①报错: zabbix_agentd [20529]: cannot create Semaphore: [28] No space left on device zabbix_agentd [205 ...
- Tronado
Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了能有效 ...
- poj3321 dfs序+树状数组单点更新 好题!
当初听郭炜老师讲时不是很懂,几个月内每次复习树状数组必看的题 树的dfs序映射在树状数组上进行单点修改,区间查询. /* 树状数组: lowbit[i] = i&-i C[i] = a[i-l ...
- Java 使用Jedis连接Redis数据库(-)
redis 安装: Linux 安装redis 1)下载jar包: 使用Jedis需要以下两个jar包: jedis-2.8.0.jar commons-pool2-2.4.2.jar 2)测试red ...
- 步步为营-71-asp.net的简单练习(图片处理)
1 原有图片添加水印 1.1 封装一个类,用于获取文件路径 using System; using System.Collections.Generic; using System.IO; using ...
- layer.js弹出框
HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- 《剑指offer》-找到数组中重复的数字
题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为 ...
- SG 大法(Sprague-Grundy函数)
SG函数的定义: g(x) = mex ( sg(y) |y是x的后继结点 ) 其中mex(x)(x是一个自然是集合)函数是x关于自然数集合的补集中的最小值,比如x={0,1,2,4,6} 则mex( ...
- JVM启动过程 类加载器
下图来自:http://blog.csdn.net/jiangwei0910410003/article/details/17733153 package com.test.jvm.common; i ...