0
我有3個選項卡;其中一個選項卡必須使用內容解析器讀取通話記錄。我在佈局中放置了4個按鈕,分別以「錯過」,「傳入」,「傳出」,「所有呼叫」來顯示這些呼叫記錄。當我點擊「未接電話」按鈕時,它只顯示listView
中的未接電話。我現在如何爲此編碼?如何使用這些按鈕來顯示?片段標籤內的按鈕
public class TabFragment2 extends Fragment {
Button b1,b2,b3,b4;
private Toolbar supportActionBar;
private FragmentManager supportFragmentManager;
ArrayList<HashMap<String, String>> Calllist1 = new ArrayList<>();
ListView callListView;
ArrayAdapter arrayAdapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.activity_call, container, false);
callListView = (ListView) view.findViewById(R.id.listView1);
Button b1 = (Button) view.findViewById(R.id.button);
/* arrayAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, Calllist1);
callListView.setAdapter(arrayAdapter);*/
getCallDetails();
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return view;
}
private void getCallDetails() {
String strOrder = CallLog.Calls.DATE + " DESC";
Uri callUri = Uri.parse("content://call_log/calls");
ContentResolver ca = getActivity().getContentResolver();
Cursor managedCursor = getActivity().getContentResolver().query(callUri, null, null, null, strOrder);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
while (managedCursor != null && managedCursor.moveToNext()) {
String phNum = managedCursor.getString(number);
String callTypeCode = managedCursor.getString(type);
String strcallDate = managedCursor.getString(date);
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm");
long seconds = managedCursor.getLong(date);
String dateString = formatter.format(new Date(seconds));
String callDuration = managedCursor.getString(duration);
String callType = null;
HashMap<String, String> callMap = new HashMap<String, String>();
callMap.put("NUMBER", phNum);
callMap.put("CALL", callTypeCode);
callMap.put("DATE", dateString);
callMap.put("DURATION", callDuration);
Calllist1.add(callMap);
int callcode = Integer.parseInt(callTypeCode);
switch (callcode) {
case CallLog.Calls.OUTGOING_TYPE:
callType = "Outgoing";
break;
case CallLog.Calls.INCOMING_TYPE:
callType = "Incoming";
break;
case CallLog.Calls.MISSED_TYPE:
callType = "Missed";
break;
}
}
managedCursor.close();
callListView.setAdapter(new CallAdapter(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, Calllist1));
}
}
你有什麼變化Abhishek先生 –