安卓案例:短信大全

隐式意图跳转的运用:

简单的布局:

Main:

<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"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

item:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:textAppearance="?android:attr/textAppearanceLarge" />

MainActivity:

package org.dreamtech.smsutil;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

    String objects[] = {
            "今天的风儿轻柔无比,今天的花儿香飘万里;今天的鸟儿十分欢喜,今天的云儿满载笑意;今天的事儿万分顺利,今天的人儿如此甜蜜。所有美...",
            "丫头,生活是你自己的,你哭它就对你哭,你笑它就对你笑。转眼,又是一年,你的生日即将来到。今年,还是少不了我对你的祝福,我忍不住...",
            "世界上最动听的声音,是妈妈声声的呼唤;世界上最温暖的笑容,是妈妈温暖的笑脸。妈妈,原谅生日时我不能陪在您身边,在这个日子里,我...",
            "今天是你的生日,祝你:发财势头如快马加鞭,一日千里;发展速度如滔滔江水,势不可挡;好事发生如雨后春笋,络绎不绝;祝福发送如比赛..." };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView lv = (ListView) findViewById(R.id.lv);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.item, objects);

        lv.setAdapter(adapter);

        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                String content = objects[position];
                Intent intent = new Intent();
                intent.setAction("android.intent.action.SEND");
                intent.addCategory("android.intent.category.DEFAULT");
                intent.setType("text/plain");
                intent.putExtra("sms_body", content);
                startActivity(intent);
            }
        });
    }

}

猜你喜欢

转载自www.cnblogs.com/xuyiqing/p/8888437.html