Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android的學習3-初識Activity

Android的學習3-初識Activity

編輯:關於Android編程

Activity---android的系統下存放控件的容器。通俗的講相當於MFC中的CFrame。搭配完成android4.4.2開發環境後,發現比2.1的開發效率高很多。

android的2.1是依靠xml添加和表述控件,但4.4.2提供了可視化的編輯工具,加快了開發速度。

\

我們添加一個按鈕,並在MainActivty.java中添加按鈕的命令響應。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+MaGiyOe6zrvxyKG/2Lz+xNg/ztLDx7Lp1MRBY3Rpdml0ebXEsO/W+s7EvP63os/W09BmaW5kVmlld0J5SWS6r8r9oaPNqLn918rUtElEy/fS/b/YvP6hozwvcD4KPHA+MqGi0ae5/WphdmG1xMjLtrzWqrXAzO2800xpc3RlbmVyxNqyv8Dgo6zKtc/WYnV0dG9utcTE2rK/z+zTpjwvcD4KPHA+M6GiYnV0dG9uyejWw7zgzP2ho7nYwarE2rK/vODM/cDgoaM8L3A+CjxwPr7fzOW0+sLryOfPwjwvcD4KPHA+PC9wPgo8cHJlIGNsYXNzPQ=="brush:java;">package com.example.myactivity; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.os.Build; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button myButton = (Button)findViewById(R.id.button1); myButton.setOnClickListener(new myButtonListener()); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); } } class myButtonListener implements OnClickListener{ @Override public void onClick(View v) { // TODO Auto-generated method stub Button myButton = (Button)findViewById(R.id.button1); myButton.setText("HelloYyxhhx"); } } @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; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } } }程序初始界面如下
\

點擊下Button


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved