Android AdapterActivity回传数据发送短信

少年意气强不羁,虎胁插翼白日飞。这篇文章主要讲述Android AdapterActivity回传数据发送短信相关的知识,希望能为你提供帮助。
一、重写BaseAdapter的getView方法

1 @Override 2 public View getView(int position, View convertView, ViewGroup parent) { 3View view; 4if (convertView == null) { 5view = View.inflate(getApplicationContext(), R.layout.item_phone, null); 6} else { 7view = convertView; 8} 9TextView name = (TextView) view.findViewById(R.id.tv_name); 10TextView phone = (TextView) view.findViewById(R.id.tv_phone); 11 12name.setText(personList.get(position).getName()); 13phone.setText(personList.get(position).getPhone()); 14 15return view; 16 }

二、ArrayAdapter构造
1 //Parameters 2 //contextThe current context. 3 //resourceThe resource ID for a layout file containing a TextView to use when instantiating views(只能有一个TextView的布局资源). 4 //objectsThe objects to represent in the ListView. 5 public ArrayAdapter (Context context, int resource, List< T> objects)

三、Activity回传数据
1、启动新Activity:startActivityForResult(intent, RequestCode);
2、新Activity回传数据(数据保存在intent中):
1 setResult(20, intent); 2 finish();

3、原Activity获取数据:
1 @Override 2 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 3if (resultCode == 10) { 4et_phone.setText(data.getStringExtra("phone")); 5} else if (resultCode == 20) { 6et_content.setText(data.getStringExtra("content")); 7} 8 }

【Android AdapterActivity回传数据发送短信】四、发送短信
1 public void btnSendMsg(View v) { 2String content = et_content.getText().toString().trim(); 3String phone = et_phone.getText().toString().trim(); 4 5SmsManager sender = SmsManager.getDefault(); 6ArrayList< String> msgList = sender.divideMessage(content); 7 8for(int i=0; i< msgList.size(); i++){ 9sender.sendTextMessage(phone, null, msgList.get(i), null, null); 10} 11 }


    推荐阅读