码迷,mamicode.com
首页 > 移动开发 > 详细

Android Adapter、Activity回传数据、发送短信

时间:2017-08-27 14:07:37      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:textview   发送   name   file   result   repr   override   object   activity   

一、重写BaseAdapter的getView方法

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

二、ArrayAdapter构造

1 //Parameters
2 //context    The current context.
3 //resource    The resource ID for a layout file containing a TextView to use when instantiating views(只能有一个TextView的布局资源).
4 //objects    The 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) {
3     if (resultCode == 10) {
4         et_phone.setText(data.getStringExtra("phone"));
5     } else if (resultCode == 20) {
6         et_content.setText(data.getStringExtra("content"));
7     }
8 }

四、发送短信

 1 public void btnSendMsg(View v) {
 2     String content = et_content.getText().toString().trim();
 3     String phone = et_phone.getText().toString().trim();
 4 
 5     SmsManager sender = SmsManager.getDefault();
 6     ArrayList<String> msgList = sender.divideMessage(content);
 7 
 8     for(int i=0;i<msgList.size();i++){
 9         sender.sendTextMessage(phone, null, msgList.get(i), null, null);
10     }
11 }

Android Adapter、Activity回传数据、发送短信

标签:textview   发送   name   file   result   repr   override   object   activity   

原文地址:http://www.cnblogs.com/leishoulin/p/7440157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!