我希望点击 holder.btnAddress 按钮打开联系人地址,并在我从联系人地址中选择一个用户后在 holder.editNumber 控件中填写电话号码。我能怎么做?谢谢!
顺便说一句,我不知道我是否可以protected void onActivityResult (int requestCode, int resultCode, Intent data)
在 ListNumberAdapter 类中添加该函数。
package ui;
import info.dodata.smsforward.R;
import java.util.List;
import bll.PublicPar;
import android.content.Context;
import android.content.Intent;
import android.provider.ContactsContract;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ListNumberAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<String> mListNumber;
private Context mContext;
public ListNumberAdapter(Context context, List<String> listNumber){
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mListNumber=listNumber;
mContext=context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mListNumber.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.sms_list_phone_number, null);
holder.tvContactName = (TextView) convertView.findViewById(R.id.tvname);
holder.editNumber = (EditText) convertView.findViewById(R.id.editnumber);
holder.btnAddress=(Button)convertView.findViewById(R.id.btnAddress);
holder.btnDelete=(Button)convertView.findViewById(R.id.btnDelete);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.id=position;
holder.tvContactName.setId(position);
holder.editNumber.setId(position);
holder.btnAddress.setId(position);
holder.btnDelete.setId(position);
holder.editNumber.setText(mListNumber.get(position));
holder.btnAddress.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
mContext.startActivity(i);
//mContext.startActivityForResult(i,0); //Don't work
}
});
return convertView;
}
}
class ViewHolder {
int id;
TextView tvContactName;
EditText editNumber;
Button btnAddress;
Button btnDelete;
}