<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > HelloWorld及Android項(xiàng)目結(jié)構(gòu)介紹

          HelloWorld及Android項(xiàng)目結(jié)構(gòu)介紹

          作者: 時(shí)間:2016-10-08 來源:網(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, 運(yùn)行一下(右鍵點(diǎn)擊你的項(xiàng)目,run as -> Android Application)看到一個(gè)按鈕了吧

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

          要為按鈕添加點(diǎn)擊事件,我們需要先得到這個(gè)對(duì)象,然后設(shè)置監(jiān)聽器,再編寫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);這句話就是用來獲取layout中設(shè)置的界面控件對(duì)象的,這個(gè)id是在button中指定的android:id=@+id/Button01 。

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


          上一頁 1 2 下一頁

          關(guān)鍵詞:

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();