1.解決了ScrollView滑動衝突問題。html
2.設置好了「查看詳解」與「題目編號」的部分。java
3.完成了app啓動圖片的設置,並在啓動的過程當中開闢新的線程鏈接服務器並開啓監聽數據。sql
別忘了註冊啓動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);設置是否能夠點擊app
5.在線程中執行Toast操做,報 Can't create handler inside thread that has not called Looper.prepare()這個運行時異常。ide
是因爲Toast依賴一個Handler來消息隊列,非主線程須要爲Toast準備Looper。oop
參考:http://blog.csdn.net/neo_86/article/details/25830443spa
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.
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(); } } }