ListFragment에 맞춤 토스트를 표시 할 소식을 찾지 못했습니다. 나는 주변을 수색했다. 여기 내 축음기를 표시하는 데 사용되는 사용자 정의 XML 파일이 있습니다.안드로이드 - ListFragment에서 맞춤 토스트를 표시하면 오류가 발생합니다.
private void delete(String course) {
DatabaseHandler db = new DatabaseHandler(this.getActivity());
boolean status = db.deleteCourse(UNI, course);
if (status) {
view = inflater.inflate(
R.layout.custom_toast_layout_course_deleted,
(ViewGroup) getActivity()
.findViewById(R.id.relativeLayout5));
Toast toast = new Toast(getActivity());
toast.setGravity(Gravity.TOP, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(view);
toast.show();
}
}
하지만 내 응용 프로그램이 실행될 때이 오류 보여줍니다 :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CC000000" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/course_deleted"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white" >
</TextView>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_margin="5dip"
android:contentDescription="@string/delete"
android:src="@drawable/ic_action_discard" >
</ImageView>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:gravity="center"
android:textColor="@android:color/white" >
</TextView>
</RelativeLayout>
이 XML을 부풀게하는 방법이다
11-13 09:48:13.521: E/AndroidRuntime(11052): FATAL EXCEPTION: main
11-13 09:48:13.521: E/AndroidRuntime(11052): java.lang.NullPointerException
11-13 09:48:13.521: E/AndroidRuntime(11052): at ......delete(POKFragment.java:173)
11-13 09:48:13.521: E/AndroidRuntime(11052): at ......access$0(POKFragment.java:161)
11-13 09:48:13.521: E/AndroidRuntime(11052): at ......onClick(POKFragment.java:107)
및 라인 173은 다음과 같습니다
view = inflater.inflate(R.layout.custom_toast_layout_course_deleted,(ViewGroup) getActivityity().findViewById(R.id.relativeLayout5));
을
이 코드의 잘못된 점은 무엇입니까? 그것은 Activity에서 잘 작동하지만 ListFragment에서는 잘못되었습니다.
view = inflater.inflate(
R.layout.custom_toast_layout_course_deleted,
null));
을 변경하는
이 주어집니다. xml은 활동 또는 귀하의 조각입니까? –
은 Toast를 표시하기 위해 Fragment에서 팽창 된 custome xml입니다. –
인플레이터가 null이 아닌 것이 확실합니까? – DrkStr