android 日常(二)

  • sqlite中用boolean類(lèi)型保存的數(shù)據(jù),因?yàn)閏ursor沒(méi)有g(shù)etBoolean()方法,取出時(shí)可用先用cursor.getInt()方法來(lái)取,若是true則為1,否則為0,然后再轉(zhuǎn)換為boolean類(lèi)型的數(shù)據(jù)
    <pre>
    </pre>

  • 錯(cuò)誤
    <pre>
    java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.example.getapninfo/com.example.getapninfo.ApnDetailActivity}:
    android.content.res.Resources$NotFoundException: String resource ID #0x1

    </pre>
    無(wú)標(biāo)題.png

    出錯(cuò)位置:
    <pre>((TextView) findViewById(R.id.title_id_show)).setText(apn.getId());
    </pre>出錯(cuò)原因:
    一般發(fā)生在參數(shù) int resId 錯(cuò)誤,你把String賦值給int的resId,所以編譯器找不到正確的resource于是報(bào)錯(cuò)。
    其中apn.getId()返回Int類(lèi)型,setText()又有幾種重載,參數(shù)類(lèi)型各不相同,所以傳入錯(cuò)誤的參數(shù)類(lèi)型會(huì)報(bào)錯(cuò)。

    應(yīng)改為:<pre>
    ((TextView) findViewById(R.id.title_id_show)).setText(""+apn.getId());
    </pre>

  • 如果要在DDMS中查看手機(jī)的文件,有的文件需要root之后才能查看
    adb root

  • 連續(xù)按兩次BACK鍵退出

private long firstTime = 0;
    @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        switch(keyCode)
        {
        case KeyEvent.KEYCODE_BACK:
             long secondTime = System.currentTimeMillis(); 
              if (secondTime - firstTime > 2000) {                                         //如果兩次按鍵時(shí)間間隔大于2秒,則不退出
                  Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); 
                  firstTime = secondTime;//更新firstTime
                  return true; 
              } else {                                                    //兩次按鍵小于2秒時(shí),退出應(yīng)用
             System.exit(0);
              } 
            break;
        }
      return super.onKeyUp(keyCode, event);
    }
  • 隱藏輸入法
方法一:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); //得到InputMethodManager的實(shí)例
if (imm.isActive()) {
//如果開(kāi)啟imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
//關(guān)閉軟鍵盤(pán),開(kāi)啟方法相同,這個(gè)方法是切換開(kāi)啟與關(guān)閉狀態(tài)的}
方法二:在onclick事件下.以下方法可行.(如果是EditText失去焦點(diǎn)/得到焦點(diǎn),沒(méi)有效果)
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容