获取listview的内容,并把这些内容通过短信发送给其他人

(1)

  获取listview的内容

 aa=(String)getData().get(arg2).get("title");

  如何跳转到发短信页面:

注:自己可以添加联系人电话号码

                               smsToUri = Uri.parse("smsto:");
    			   mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
    			  mIntent.putExtra("sms_body", aa);
    			  startActivity( mIntent );

(2)

 布局文件1

<?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" >
    
<TextView 
     android:id="@+id/title"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
      
    />
</LinearLayout>

布局文件2

<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/listview"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"      
        >
   </ListView>

</RelativeLayout>

(3)主文件

package com.example.phone;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class MainActivity extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		ListView listView = (ListView) findViewById(R.id.listview);
		SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.content, new String[]{"title"}, new int[]{R.id.title});
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(listenter);		
	}
     OnItemClickListener listenter = new OnItemClickListener() {
    	 @Override
    	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
    			long arg3) {
    		    String aa = null;
    		    Uri smsToUri= null;
    		    Intent mIntent = null;
    		  switch(arg2){
    		  case 0:
    			   aa=(String)getData().get(arg2).get("title");
    			  Toast.makeText(MainActivity.this,  aa,Toast.LENGTH_LONG).show();
    			   smsToUri = Uri.parse("smsto:");
    			   mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
    			  mIntent.putExtra("sms_body", aa);
    			  startActivity( mIntent );
    			  break;
    		  case 1:
    			   aa=(String)getData().get(arg2).get("title");
    			  Toast.makeText(MainActivity.this,  aa,Toast.LENGTH_LONG).show();
    			   smsToUri = Uri.parse("smsto:");
    			  mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
    			  mIntent.putExtra("sms_body", aa);
    			  startActivity( mIntent );
    			  break;
    		  case 2:
    			  aa=(String)getData().get(arg2).get("title");
    			  Toast.makeText(MainActivity.this, aa,Toast.LENGTH_LONG).show();
    			   smsToUri = Uri.parse("smsto:");
    			   mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
    			  mIntent.putExtra("sms_body", aa);
    			  startActivity( mIntent );
    			  break;	      		    
    		  }	
    		  
    		 
    	}
	};  	 
	private List<Map<String, Object>> getData()
	{
		 List<Map<String, Object>> list = 
				 new ArrayList<Map<String,Object>>();
		 Map<String, Object> map =
				 new HashMap<String, Object>();
		 map.put("title", "刘祖义");
		 list.add(map);
		 
		 map=new HashMap<String, Object>();
		 map.put("title", "QQ592003516");
		 list.add(map);
		  
		 map =new HashMap<String, Object>();
		 map.put("title", "微信liuzuyi2007");
		 list.add(map);
		return list;
	}

}



你可能感兴趣的:(获取listview的内容,并把这些内容通过短信发送给其他人)