安卓開發學習中的筆記,遇到什麼寫什麼
1. 獲取view的子view
public void onClick(View v) {
LinearLayout ll = (LinearLayout) findViewById(v.getId()); //最外面那層,也就是v
RelativeLayout rl = (RelativeLayout) ll.getChildAt(0); //v內部的RelativeLayout
TextView tv = (TextView) rl.getChildAt(0);//RelativeLayout 內部的TextView
}
要驗證對不對:
if (tv.getId() == R.id.c501_tag) { //c501_tag就是我在xml文件中給TextView取的id
System.out.println("tv==c501_tag");
}
結果: