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(); } } }