短信大全简单demo

Java小白修炼手册


短信大全简单demo_第1张图片

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    String[] objects = {"最幸福的爱,就是找到了你。我纵容你的习惯,宽容你的折腾,爱着你的一切。你的心是我最好的房子,一起柴米油盐,一起细水长流,然后一起相守着慢慢变老,从此陪伴一生。爱你,一辈子,永不改变。",
            "留一个特别的座位给你,在我怀里;留一道特别的风景给你,在我眼里;留一丝特别的思念给你,在我脑海里;在有风的日子,我叮嘱风儿,让风替我亲吻你;在有阳光的日子,让阳光替我问候你;在有雨的日子,让雨替我祝福你;我只想告诉你,我的生命里不能没有你!",
            "如果你一生气,对方就立刻听你的,那是怕你,怕是因为爱。你一发嗲,对方就立刻听你的,那是宠你,宠也是因为爱。你一难过,对方就立刻听你的,那是疼你,疼也是因为爱。对你好有三个标志,要么怕你,要么宠你,要么疼你。",
            "我想让清风把我的思念捎给你,可清风说我的思念太重,怕驮不动;我想让星星把我的吻捎给你,可星星说我的吻太浓,怕会消融;我想让流水把我的爱送给你,可流水说我的爱太热烈,怕会蒸发;我只好借短信告诉你,我的情永远为你而钟!",
            "路,有点雾,雾散留下了露珠,这露珠丰满了爱的泥土。爱情路。弯弯路,弯得像一串珍珠,每一步都有简单的领悟。我只想,每个朝朝暮暮,都和你共度。让手心一直都热乎乎,有种缓慢的幸福,伴随一点辛苦。与你相守就是幸福!",
            "真正的爱情,要懂得珍惜:没有谁和谁是天生就注定在一起的。一辈子其实不长,能遇到心爱的人,是多么幸运的事,为何不紧握着他的手呢。一辈子只爱一个人,不丢人。一颗心需要去温暖另一颗心,坦诚相待,这样才可以幸福。"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView listView = findViewById(R.id.lv);
        
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.item,R.id.textView ,objects);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String content = objects[position];
                Uri smsToUri = Uri.parse("smsto:");
                Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri);
                intent.putExtra("sms_body", content);
                startActivity(intent);
            }
        });
    }
}

以下界面使用ConstraintLayout可视化编程(就是用Android Studio画出来的)
activity_main.xml

"1.0" encoding="utf-8"?>
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">

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



item.xml

"1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.13"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

AndroidManifest.xml

"1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.message">
    android:name="android.permission.SEND_SMS"/>
    android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        android:name=".MainActivity">
            
                android:name="android.intent.action.MAIN" />

                android:name="android.intent.category.LAUNCHER" />
            
        
    


你可能感兴趣的:(#,安卓开发)