我想为不同的联系人添加不同的对话框..!! 我想在下面的for循环中创建,这是我的代码..!!
public class CallActivity extends Activity{
sqlAdapter adapter;
Context mContext;
String Birthdate, CurrentDate, ctName = "Unknown", phNumber = "Unknown";
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder);
Calendar cal = Calendar.getInstance();
int date = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH)+1;
/* 获取当前日期 */
if(date<10 && month<10){
CurrentDate = "0"+month+"-0"+date;
Toast.makeText(getBaseContext(), "CurrentDate : " + CurrentDate, Toast.LENGTH_LONG).show();
}else if(month<10 && date>10){
CurrentDate = "0"+month+"-"+date;
Toast.makeText(getBaseContext(), "CurrentDate : " + CurrentDate, Toast.LENGTH_LONG).show();
}else if(month>9 && date<10){
CurrentDate = month+"-0"+date;
Toast.makeText(getBaseContext(), "CurrentDate : " + CurrentDate, Toast.LENGTH_LONG).show();
}else {
CurrentDate = month+"-"+date;
Toast.makeText(getBaseContext(), "CurrentDate : " + CurrentDate, Toast.LENGTH_LONG).show();
}
adapter = new sqlAdapter(getBaseContext());
adapter.openToRead();
ArrayList<ContactDetails> cDetails = adapter.getContactDetails(CurrentDate);
adapter.close();
/* 这是 for 循环,我想为不同的联系人生成警报对话框 */
for (int i = 0; i < cDetails.size(); i++) {
ctName = cDetails.get(i).Name;
adapter.openToRead();
phNumber = adapter.getcNumber(ctName);
adapter.close();
alertforcall(getBaseContext(),ctName,phNumber);
}
}
public void alertforcall(Context context, String Name, final String ctNumber){
mContext = context;
AlertDialog alert = new AlertDialog.Builder(CallActivity.this).create();
alert.setIcon(R.drawable.ic_launcher);
alert.setTitle("");
alert.setMessage("Are you sure want to call " + Name +"? " );
alert.setButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
alert.setButton2("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String phoneNumber = "tel:" + ctNumber;
Intent intent = new Intent(Intent.ACTION_CALL, Uri
.parse(phoneNumber));
startActivity(intent);
finish();
}
});
alert.show();
}