当前位置:操作系统 > 安卓/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.布局

 

 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,