我有一个自定义listView,我在其中通过自定义适配器设置内容。我无法了解如何进行不同的操作。 我只有一个Activity扩展活动类,我在“onPostExecute()”中调用我的自定义适配器。如何使电话,短信和电子邮件功能正常工作。
以下是我的代码
protected void
onPostExecute(String result) {
super.onPostExecute(result);
ListAdapter adapter = new AdapterListView(
AndroidJSONParsingActivity.this, contactList,
R.layout.list_item, new String[] { TAG_COMPANY_NAME, TAG_EMAIL,TAG_PERSON_DESIGNATION ,TAG_NUMBER},
new int[] { R.id.name, R.id.email,R.id.designation,R.id.phone });
// if (ImageURL != null && ImageURL != "")
// imageloader.displayImage(Utils.getEncodedUrl(ImageURL),
// logo_icon_image, options);
list.setAdapter(adapter);
dialog.dismiss();
};
}
答案 0 :(得分:5)
您可以使用SmsManager或通过调用内置SMS应用程序发送短信
<强> 1。使用SmsManager API发送短信
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("", null, "< message body>", null, null);
SmsManager要求你的android mainfeast中的SMS_SEND权限。
<强> 2。通过调用内置SMS应用程序发送短信
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", “");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
第3。发送电子邮件
String to = toEmail.getText().toString();
String subject = emailSubject.getText().toString();
String message = emailBody.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
// need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client"));
<强> 4。在android中调用
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:0377778888"));
startActivity(callIntent);
您可以从以下链接中找到完整的教程
Sending SMS Message In Android
修改-1 强>
您可以使用以下代码段来处理列表点击事件
lv1.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
// write your code here
}
});
如果每个列表行都有视图来处理事件,那么您可以使用ViewHolder设计模式在适配器getView方法中单独处理。
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_row_layout, null);
holder = new ViewHolder();
holder.button = (Button) convertView.findViewById(R.id.button);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if(button!=null){
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
}
return convertView;
}
static class ViewHolder {
Button button;
}