想飛就別怕摔

          大爺?shù)牟M罵人

          Android學(xué)習(xí)筆記(一)初步Activity與Intent【乘法運(yùn)算】

          MyActivity.java
          package zzn.android;

          import android.app.Activity;
          import android.content.Intent;
          import android.net.Uri;
          import android.os.Bundle;
          import android.view.Menu;
          import android.view.MenuItem;
          import android.view.View;
          import android.widget.Button;
          import android.widget.EditText;
          import android.widget.TextView;

          public class MyActivity extends Activity
          {
              /** Called when the activity is first created. */
              private Button myButton = null;
              private EditText myEdit01;
              private EditText myEdit02;
              private TextView myText01;
              @Override
              public void onCreate(Bundle savedInstanceState)
              {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);

                  myEdit01 = (EditText)findViewById(R.id.edit01);
                  myEdit02 =(EditText)findViewById(R.id.edit02);
                  myText01 = (TextView)findViewById(R.id.text01);
                  myButton = (Button)findViewById(R.id.myButton);

                  myText01.setText(R.string.textView01);
                  myButton.setText(R.string.myButton);
                  myButton.setOnClickListener(new MyButtonListener());
                  }

              // 當(dāng)點(diǎn)擊鍵盤上的menu按鈕時調(diào)用此方法。
              @Override
              public boolean onCreateOptionsMenu(Menu menu) {
              menu.add(1,1,1,R.string.exit);
              menu.add(1,2,2,R.string.about);
              return super.onCreateOptionsMenu(menu);
          }

              @Override
              public boolean onOptionsItemSelected(MenuItem item) {
                  if(item.getItemId() == 1){
                      finish();
                  }
                  return super.onOptionsItemSelected(item);
              }

              class MyButtonListener implements View.OnClickListener {
                  @Override
                  public void onClick(View view) {
                      String  edit01Str = myEdit01.getText().toString();
                      String edit02Str = myEdit02.getText().toString();

                      Intent intent = new Intent();
                      intent.putExtra("edit01",edit01Str);
                      intent.putExtra("edit02",edit02Str);

                      intent.setClass(MyActivity.this,MyActivity01.class);
                      startActivity(intent);

                      //生成一個Intent對象
                     /* Intent intent = new Intent();
                      intent.putExtra("testExtra","123456");
                      intent.setClass(MyActivity.this,MyActivity01.class);
                      MyActivity.this.startActivity(intent);
          */

                      /*Uri uri = Uri.parse("smsto://0800000123");
                      Intent intent   = new Intent(Intent.ACTION_SENDTO,uri);
                      intent.putExtra("sms_body","this is sms test");
                      startActivity(intent);
          */

                  }
              }

          }

          MyActivity02.java
          package zzn.android;

          import android.app.Activity;
          import android.content.Intent;
          import android.os.Bundle;
          import android.widget.TextView;

          public class MyActivity01 extends Activity {
              private TextView myTextView = null;
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.other);
                  Intent intent = getIntent();
                  String edit01Str = intent.getStringExtra("edit01");
                  String edit02Str = intent.getStringExtra("edit02");
                  int intEdit01 = Integer.parseInt(edit01Str);
                  int intEdit02 = Integer.parseInt(edit02Str);
                  int result = intEdit01*intEdit02;
                  myTextView = (TextView)this.findViewById(R.id.myTextView);
                  myTextView.setText(result+"");
              }
          }

          main.xml
          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation
          ="vertical"
              android:layout_width
          ="fill_parent"
              android:layout_height
          ="fill_parent"
              
          >
              <EditText
                  
          android:id="@+id/edit01"
                  android:layout_width
          ="fill_parent"
                  android:layout_height
          ="wrap_content"
                  
          />
              <TextView
                  
          android:id="@+id/text01"
                  android:layout_height
          ="wrap_content"
                  android:layout_width
          ="fill_parent"
                  
          />
              <EditText
                      
          android:id="@+id/edit02"
                      android:layout_width
          ="fill_parent"
                      android:layout_height
          ="wrap_content"
                      
          />

              <Button
                  
          android:id="@+id/myButton"
                  android:layout_width
          ="fill_parent"
                  android:layout_height
          ="wrap_content"
          android:text
          ="點(diǎn)擊我跳轉(zhuǎn)"    />
          </LinearLayout>

          other.xml
          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:orientation
          ="vertical"
                        android:layout_width
          ="fill_parent"
                        android:layout_height
          ="fill_parent"
                  
          >

              <TextView
                  
          android:id="@+id/myTextView"
                  android:layout_width
          ="fill_parent"
                  android:layout_height
          ="wrap_content"
                  
          />
          </LinearLayout>

          String.xml
          <?xml version="1.0" encoding="utf-8"?>
          <resources>
              <string name="app_name">myAndroid01</string>
              <string name="myTextView">otherActivity</string>
              <string name="textView01">乘以</string>
              <string name="myButton">計(jì)算結(jié)果</string>
              <string name="exit">退出</string>
              <string name="about">關(guān)于</string>
          </resources>

          AndroidManifest.xml
          <?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                    package
          ="zzn.android"
                    android:versionCode
          ="1"
                    android:versionName
          ="1.0">
              <uses-sdk android:minSdkVersion="8"/>
              <application android:label="@string/app_name">
                  <activity android:name="MyActivity"
                            android:label
          ="@string/app_name">
                      <intent-filter>
                          <action android:name="android.intent.action.MAIN"/>
                          <category android:name="android.intent.category.LAUNCHER"/>
                      </intent-filter>
                  </activity>

                  <activity android:name="MyActivity01"
                            android:label
          ="@string/myTextView"/>


              </application>
          </manifest> 







          posted on 2012-05-28 11:32 生命的綻放 閱讀(410) 評論(0)  編輯  收藏 所屬分類: Android


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2012年5月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(5)

          隨筆分類(94)

          隨筆檔案(93)

          文章分類(5)

          文章檔案(5)

          相冊

          JAVA之橋

          SQL之音

          兄弟之窗

          常用工具下載

          積分與排名

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 当涂县| 松桃| 兴山县| 庄浪县| 长寿区| 翁牛特旗| 巧家县| 叙永县| 泗阳县| 平江县| 苍溪县| 太原市| 宝清县| 阿拉善盟| 桐柏县| 罗山县| 梁山县| 无为县| 宁河县| 元谋县| 驻马店市| 商丘市| 霍州市| 佛坪县| 开江县| 教育| 大英县| 海兴县| 栖霞市| 大港区| 团风县| 台东市| 阿坝县| 巩留县| 芜湖县| 广宁县| 眉山市| 白玉县| 上思县| 六盘水市| 安泽县|