gpt4 book ai didi

android - 如何将 datepickerdialog 中选定的日期传递给 Cursor

转载 作者:行者123 更新时间:2023-11-29 22:10:59 25 4
gpt4 key购买 nike

我正在编写一个代码,用于使用日期选择器对话框获取选定日期的未接来电列表。我正在使用按钮来显示选定的日期。我能够获取未接来电列表并能够选择日期,但我不确定如何将所选日期传递到光标查询以获取该日期的未接来电列表。

public class missnew extends ActionBarActivity implements View.OnClickListener,DatePickerDialog.OnDateSetListener,SwipeRefreshLayout.OnRefreshListener{

private int day;
private int month;
private int year;
private Calendar calender;
private Button button;
private TextView textView;
private ScrollView scrollview;
private DatePickerDialog datePickerDialog;
private SwipeRefreshLayout swipeRefreshLayout;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_missnew);

button = (Button)findViewById(R.id.button);
textView = (TextView)findViewById(R.id.textview);
scrollview = (ScrollView)findViewById(R.id.scrollView);

swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe);
swipeRefreshLayout.setOnRefreshListener(this);
//swipeRefreshLayout.setColorSchemeColors(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
// android.R.color.holo_orange_light, android.R.color.holo_red_light);

swipeRefreshLayout.setDistanceToTriggerSync(20);
swipeRefreshLayout.setSize(1);


calender = Calendar.getInstance(Locale.getDefault());

button.setOnClickListener(this);

day=calender.get(Calendar.DAY_OF_MONTH);
month=calender.get(Calendar.MONTH);
year=calender.get(Calendar.YEAR);

setupdate(day, month, year);

// calender.set(year,month,day);
//String fromDate = String.valueOf(calender.getTimeInMillis());
getCallDetails();
}

private void getCallDetails()
{

StringBuffer sb = new StringBuffer();
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
String Fdate = (day+"-"+(month+1) +"-"+year);
// String selection = CallLog.Calls.DATE + ">?", new String[] { String.valueOf(Fdate.getBytes())};
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyy");


// Long l = Long.parseLong(Fdate);


Cursor managedCursor = getContentResolver().
query(
android.provider.CallLog.Calls.CONTENT_URI,
null,
null,
null,
strOrder);
sb.append("Missed Calls :");


while (managedCursor.moveToNext())
{
String phNumber = managedCursor.getString(managedCursor.getColumnIndex(CallLog.Calls.NUMBER));
String callType = managedCursor.getString(managedCursor.getColumnIndex(CallLog.Calls.TYPE));
String callDate = managedCursor.getString((managedCursor.getColumnIndex(CallLog.Calls.DATE)));
String callname= managedCursor.getString(managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME));

Date callDayTime = new Date(Long.valueOf(callDate));
String Tdate=formatter.format(callDayTime);

String dir = null;
int dircode = Integer.parseInt(callType);


if(dircode==CallLog.Calls.MISSED_TYPE){

sb.append("\nPhone Number:--- " + phNumber +
" \nCall Date:--- " + l + "\nName:---" +callname);
sb.append("\n----------------------------------"); }
}//managedCursor.close();

textView.setText(sb);
}





private void setupdate(int day, int month, int year) {

button.setText(String.valueOf(day) + "/" + String.valueOf(month + 1) + "/" +String.valueOf(year));


}


@Override
public void onClick(View v) {

switch (v.getId()){
case R.id.button:
showdate();
break;
default:
//do nothing
break;
}

}

private void showdate() {
datePickerDialog = new DatePickerDialog(
this
,missnew.this
,year
,month
,day);
datePickerDialog.show();
}

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
setupdate(year,monthOfYear,dayOfMonth);


}

@Override
public void onRefresh() {
(new Handler()).postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
getCallDetails();
}
}, 5000);

}
}

最佳答案

使用此功能可以根据日期获取通话列表。我只是按照你的代码写的,

String dateText = button.getText(); // Time in millsec

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); // assuming date text is in "MM/dd/yyyy" format and I'm doing this.
Date date = sdf.parse(dateText);


Cursor c = contentResolver.query(CallLog.Calls.CONTENT_URI,
null,
CallLog.Calls.DATE + ">?",
new String[] { String.valueOf(date.getTime())},
strOrder);

关于android - 如何将 datepickerdialog 中选定的日期传递给 Cursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31675859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com