<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > HelloWorld及Android項目結構介紹

HelloWorld及Android項目結構介紹

作者: 時(shí)間:2016-10-08 來(lái)源:網(wǎng)絡(luò ) 收藏

setContentView(R.layout.hello_world);

}

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.hello_world);

}

R.layout.hello_world 就指向 hello_world.xml,同理 R.string.click_me就向Click

me, 運行一下(右鍵點(diǎn)擊你的項目,run as -> Android Application)看到一個(gè)按鈕了吧

6 為按鈕添加點(diǎn)擊事件:

要為按鈕添加點(diǎn)擊事件,我們需要先得到這個(gè)對象,然后設置監聽(tīng)器,再編寫(xiě)onClick事件

完成后代碼如下:

Java代碼

import android.app.Activity;

import android.app.AlertDialog;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class HelloWorld extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.Button01);

button.setOnClickListener(new OnClickListener(){

public void onClick(View arg0) {

openDialog();

}

});

}

private void openDialog(){

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle(Hello);

builder.setMessage(Hello World n);

builder.setNegativeButton(OK,null);

builder.show();

}

}

import android.app.Activity;

import android.app.AlertDialog;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class HelloWorld extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.Button01);

button.setOnClickListener(new OnClickListener(){

public void onClick(View arg0) {

openDialog();

}

});

}

private void openDialog(){

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle(Hello);

builder.setMessage(Hello World n);

builder.setNegativeButton(OK,null);

builder.show();

}

}

Button button = (Button)findViewById(R.id.Button01);這句話(huà)就是用來(lái)獲取layout中設置的界面控件對象的,這個(gè)id是在button中指定的android:id=@+id/Button01 。

Android的UI用起來(lái)跟SWT是很像的,以后我會(huì )挑一些常用的,有趣的UI控件詳細地介紹一下。今天先寫(xiě)到這里,每次我都會(huì )把相應項目的源代碼貼到最下面。


上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>