不多解释,直接上代码:
MainActivity.java代码
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
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[] = {"今天的风儿轻柔无比,今天的花儿香飘万里;今天的鸟儿十分欢喜,今天的云儿满载笑意;今天的事儿万分顺利,今天的人儿如此甜蜜。所有美...","丫头,生活是你自己的,你哭它就对你哭,你笑它就对你笑。转眼,又是一年,你的生日即将来到。今年,还是少不了我对你的祝福,我忍不住...",
"世界上最动听的声音,是妈妈声声的呼唤;世界上最温暖的笑容,是妈妈温暖的笑脸。妈妈,原谅生日时我不能陪在您身边,在这个日子里,我...",
"春天的鲜花,夏天的浪花,秋天的繁华,冬天的雪花,不论何时何地都希望你乐开花,朋友,在这阳光明媚的日子,我为你放飞一群祝福,祝你..."};
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), 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-filter>
<action android:name="android.intent.action.SEND"/>
category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>*/
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);//sms_body需要查系统源码
startActivity(intent);
}
});
}
}
activity_main.xml
<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="com.example.message.MainActivity" >
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
Android上层系统应用的源代码 : 点击打开链接