Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android開發點點滴滴

Android開發點點滴滴

編輯:關於Android編程

本文在不斷更新中。。。。

1.字符串比較

我在獲取EditText中的內容時,初始時得到的是"",然後我直接判斷edittextString=="",結果怎麼都跳入,記得MFC中比較好像可以直接這樣,然後改為edittextString.equals("")正確。

[java]
if(!tmpString.equals("")) 

tmpString+="/"; 

if(!tmpString.equals(""))
{
tmpString+="/";
}2.string操作

和MFC中CString類一樣有很多方法,其中我比較喜歡的是split分割字符串,這個在CString中貌似沒有,但是string沒有find(有indexof可以實現)。(詳細見點此)

3.int與string轉換

 


4.組件的操作

android中組件的操作都是通過id來實現的(findViewById()),對於一組組件的操作,我首先想到,id是int型的,那我直接對於id可以數學操作,得到我想要的id,然後findViewById(),例如

[java]
id=0x7f050000+timeInt*7+weekInt; 
textView=(TextView)findViewById(id); 

id=0x7f050000+timeInt*7+weekInt;
textView=(TextView)findViewById(id);但是發現這樣並不好(移植性等)

然後發現可以定義一個id的int型數組,例如


[java]
int[] weeks=new int[]{ 
            R.id.week1, 
            R.id.week2, 
            R.id.week3, 
            R.id.week4, 
            R.id.week5, 
            R.id.week6, 
            R.id.week7, 
            R.id.week8, 
            R.id.week9, 
            R.id.week10, 
            R.id.week11, 
            R.id.week12, 
            R.id.week13, 
            R.id.week14, 
            R.id.week15, 
            R.id.week16, 
            R.id.week17, 
            R.id.week18, 
            R.id.week19, 
            R.id.week20          
}; 

int[] weeks=new int[]{
   R.id.week1,
   R.id.week2,
   R.id.week3,
   R.id.week4,
   R.id.week5,
   R.id.week6,
   R.id.week7,
   R.id.week8,
   R.id.week9,
   R.id.week10,
   R.id.week11,
   R.id.week12,
   R.id.week13,
   R.id.week14,
   R.id.week15,
   R.id.week16,
   R.id.week17,
   R.id.week18,
   R.id.week19,
   R.id.week20   
};這樣操作起來,和數組序號對應以來,操作很方便,


[java]
for(int i=0;i<weeks.length;i++) 

checkBox=(CheckBox)findViewById(weeks[i]); 
checkBox.setChecked(false); 

for(int i=0;i<weeks.length;i++)
{
checkBox=(CheckBox)findViewById(weeks[i]);
checkBox.setChecked(false);
}5.數據庫操作

6.布局

 

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved