欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開(kāi)發(fā)之創(chuàng)建可點(diǎn)擊的Button實(shí)現(xiàn)方法

 更新時(shí)間:2016年03月31日 10:07:09   作者:程序詩(shī)人  
這篇文章主要介紹了Android創(chuàng)建可點(diǎn)擊的Button實(shí)現(xiàn)方法,實(shí)例分析了Android創(chuàng)建button按鈕過(guò)程中的界面配置,功能實(shí)現(xiàn)與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Android創(chuàng)建可點(diǎn)擊的Button實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

感覺(jué)到自己有必要學(xué)習(xí)下手機(jī)開(kāi)發(fā)方面的知識(shí),不論是為了以后的工作需求還是目前的公司項(xiàng)目。

當(dāng)然,任何新東西的開(kāi)始,必然伴隨著第一個(gè)HelloWorld,Android學(xué)習(xí)也不例外。既然才開(kāi)始,我就不做過(guò)多的描述了。

對(duì)于Android開(kāi)發(fā)的IDE:ADT來(lái)說(shuō),打開(kāi)的第一眼有點(diǎn)迷糊,不過(guò)看了網(wǎng)上各種目錄結(jié)構(gòu)的介紹,慢慢的就明白了,做這個(gè)實(shí)例,我們尤其需要關(guān)注兩個(gè)地方,一個(gè)是src目錄,一個(gè)就是res目錄下的layout目錄。src目錄放置的是code-behind源碼,而layout目錄放置的則是xml前臺(tái)配置文件。

既然我們要實(shí)現(xiàn)的功能是點(diǎn)擊按鈕,然后EditText中顯示“Hello World!”。讓我們先打開(kāi)layout文件,拖放一個(gè)Button上去,然后拖放一個(gè)EditText上去,最后的xml文件結(jié)構(gòu)如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" >
  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:text="Button" />
  <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_toRightOf="@+id/button1"
    android:text="EditText" />
</RelativeLayout>

然后在后臺(tái)代碼文件中,我們需要引入兩個(gè)命名空間:

import android.widget.Button;
import android.widget.EditText;

全部代碼如下:

package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
  private Button myButton;
  private EditText myText;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myButton = (Button)findViewById(R.id.button1);
    myText = (EditText)findViewById(R.id.editText1);
    myButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        myText.setText("Hello World!");
      }
    });
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }
}

然后點(diǎn)擊運(yùn)行按鈕,在虛擬機(jī)界面中點(diǎn)擊按鈕,得到的結(jié)果如下圖:

這節(jié)就到這里了,后面我們會(huì)繼續(xù)探秘。

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論