extends ListActivity
由于extend ListFragment
代码建议,我正在从 2 个类别进行转换。
据我所知,Fragment 与 Activity 有关,所以首先使用getActivity()...
应该做的工作是适应大多数方法。其他时候,我已经定义Activity activity_context;
并使用它。
无论如何,我有一些我无法适应的功能,我需要一些帮助。
第一个是: RecentCallsListActivity extends Fragment
public class RecentCallsListActivity extends ListFragment
...
private static final class QueryHandler extends AsyncQueryHandler {
private final WeakReference<RecentCallsListActivity> mActivity;
...
public QueryHandler(Context context) {
super(context.getContentResolver());
mActivity = new WeakReference<RecentCallsListActivity>(
(RecentCallsListActivity) context); //GETTING THE ERROR HERE
}
错误:无法从上下文转换为 RecenCallsListActivity
public void onActivityCreated(Bundle state) {
super.onActivityCreated(state);
mQueryHandler = new QueryHandler(activity_context);
第二个是: CallDetailActivity extends Fragment
public class CallDetailActivity extends ListFragment
...
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_CALL: {
// Make sure phone isn't already busy before starting direct call
TelephonyManager tm = (TelephonyManager)
getActivity().getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
Intent callIntent = new Intent(Intent.ACTION_CALL,
Uri.fromParts("tel", mNumber, null));
startActivity(callIntent);
return true;
}
}
}
return super.onKeyDown(keyCode, event); //GETTING IT HERE
}
错误:未定义 ListFragment 类型的方法 onkeyDown(int, keyevent)