android开发入门--------1两个简单界面以及跳转+跳转到发短信

来源:互联网 发布:淘宝对新店有什么扶持 编辑:程序博客网 时间:2024/05/18 01:19

mainfest文件代码   文件名 :AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.first"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="18" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.first.MainActivity"            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=".Activity2" android:label="ac2"/>      </application></manifest>



以下为main activity的布局文件  文件名  : activity_main.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:orientation = "vertical"    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" >    <TextView        android:id="@+id/textid"        android:layout_width="match_parent"        android:layout_height="20sp"/>                         <Button        android:id="@+id/buttonid"        android:layout_width="match_parent"        android:layout_height="wrap_content"                         />    </LinearLayout>


以下为mainactivity的代码   文件名: MainActivity.java


package com.first;import android.app.Activity;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.view.View.OnClickListener;public class MainActivity extends Activity {private Button butt= null;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        TextView tt =(TextView)findViewById(R.id.textid);        butt =(Button)findViewById(R.id.buttonid);        tt.setText("sdfasdf");        butt.setText("button1111");            butt.setOnClickListener(new myOnclickListener());     }        class myOnclickListener implements OnClickListener{@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent myintent = new Intent();myintent.putExtra("dakai", "lodfgdzfgfgve");myintent.setClass(MainActivity.this, Activity2.class);MainActivity.this.startActivity(myintent);}        }                   @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;    }    }



以下是activity2 的布局文件   文件名: activity2.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"     >            <Button        android:id="@+id/button3"        android:layout_width="match_parent"        android:layout_height="wrap_content"              />     <TextView        android:id="@+id/textid33"        android:layout_width="match_parent"        android:layout_height="20sp"/></LinearLayout>



以下为activity2的代码文件 文件名  :Activity2.java


/** *  *//** * @author yzz * */package com.first;import android.app.Activity;import android.content.DialogInterface;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.view.View.OnClickListener;public class Activity2 extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity2);Button tt2 = (Button)findViewById(R.id.button3);tt2.setText("adsa");Intent dd1 =getIntent();String txt=dd1.getStringExtra("dakai");TextView tt21= (TextView)findViewById(R.id.textid33);tt21.setText(txt);tt2.setOnClickListener(new myOnclickListener1());}class myOnclickListener1 implements OnClickListener{@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//myintent.setClass(MainActivity.this, Activity2.class);//MainActivity.this.startActivity(myintent);Uri uri1 = Uri.parse("smsto:18311033750");Intent intent11 = new Intent (Intent.ACTION_SENDTO,uri1);intent11.putExtra("sms_body", "The SMS text");startActivity(intent11);}        }} 



0 0
原创粉丝点击