【发布时间】:2014-03-26 05:14:05
【问题描述】:
我想从另一个片段运行单个片段。我试试:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.lecturers_fragment,
container, false);
ListView list = (ListView) rootView.findViewById(R.id.lecturersList);
final List<Lecturer> allLecturersList = LecturerDatabaseHelper
.getAllLecturers(getActivity());
if (allLecturersList != null) {
LecturerItemAdapter lecturerAdapter = new LecturerItemAdapter(
mCurrentActivity, allLecturersList);
list.setAdapter(lecturerAdapter);
}
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
int index, long id) {
Lecturer lecturer = allLecturersList.get(index);
L.i("Boulder name is playing link it contains"
+ lecturer.getName());
Intent intent_lecturer = new Intent(mCurrentActivity,
LecturerFragment.class);
intent_lecturer.putExtra(LecturerFragment.SELECTED_LECTURER,
lecturer);
mCurrentActivity.startActivity(intent_lecturer);
}
});
return rootView;
}
在我的 logcat 中,我有这个:
03-25 22:04:36.092: E/AndroidRuntime(12453): Caused by: java.lang.ClassCastException: com.asi.sesjaapp.view.LecturerFragment cannot be cast to android.app.Activity
我该怎么做?
【问题讨论】:
-
我今天已经回答了这个问题:stackoverflow.com/a/22637001/2668136^^
-
你不能写
new Intent(mCurrentActivity, LecturerFragment.class)然后mCurrentActivity.startActivity(intent_lecturer);,因为LecturerFragment类继承自Fragment,而不是Activity。 -
Fllo 但我从另一个片段而不是活动中运行它。
-
@Json 我的错,对不起;)
标签: java android android-fragments