我實際上並沒有問題,只是想請你解釋我這個代碼Android。實例化一個接口?
public class HeadlinesFragment extends ListFragment {
OnHeadlineSelectedListener mCallback;
// Container Activity must implement this interface
public interface OnHeadlineSelectedListener {
public void onArticleSelected(int position);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (OnHeadlineSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
...
}
這是關於實施接口的方法的類對象? 即使是,請解釋一下 謝謝
如果你不知道你在做什麼,請隨時刪除它。這是一個回調,它似乎在創建片段時自動生成。 – Vucko
沒有人 看看這 – Zgodni