Android现学现用第一天
1.Mac 系統下Eclipse還是挺好用的,蘋果對于Android的支持不錯。Mac下的Eclipse的菜單在最上面的蘋果菜單欄里,不要亂翻了。使用起來和Windows下的Eclipse差不多。
2.src,gen和res是三個主要的部分。src是java源碼部分,gen是自動生成的,res里是圖片資源和頁面控件,draw里面是圖片,layout中的xml是控件信息,這里更改后保存,gen中直接就變了。value是一些變量的值。
3.layout xml中注冊控件是這樣的:
<Button ?
? ? android:id="@+id/report_button"
? ? android:layout_width="fill_parent"?
? ? android:layout_height="wrap_content"?
? ? android:text="Report YAMI!"
? ? />
gen中的R類里是這樣自動生成的:
?public static final class id {
? ? ? ? public static final int report_button=0x7f050001;
? ? ? ? public static final int search_button=0x7f050000;
? ? ? ? public static final int textview=0x7f050002;
? ? }
SRC中是這樣引用的:
public void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.main);
? ? ? ? search_now();
? ? ? ? report_now();
? ? }
private Button.OnClickListener button_report_listener = new Button.OnClickListener(){
? ? @Override
public void onClick(View v) {
//跳轉頁面
? ? setTitle("To indicate report!");
}
? ? };
private void report_now(){
? ? Button button_report = (Button)findViewById(R.id.report_button);
button_report.setOnClickListener(button_report_listener);
}
直接定義監聽器,在方法中就把button控件定義好了,在把定義好的監聽器放進去就行。
最后加一句,helloworld創建工程后直接就能顯示出來了,不用找源代碼了。甚至不需要以前還要system.out.println...白找了那么久
轉載于:https://www.cnblogs.com/NateSheng/archive/2011/09/01/2162528.html
總結
以上是生活随笔為你收集整理的Android现学现用第一天的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Day 43 索引
- 下一篇: 自定义Chrome 滚动条样式