Warum verursacht meine setVisibility (View.INVISIBLE) Ausnahme, während setVisibility für TextView funktioniert. Ich habe auch versucht es für Image gesetzt und es funktioniert auch nicht - ich Ausnahme auch immer binsetVisibility (View.INVISIBLE) verursacht Ausnahme, warum?
public void alertdiag() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alertdiag_layout, null);
dialogBuilder.setView(dialogView).show();
View Divider1 = (View) dialogView.findViewById(R.style.Divider1);
Divider1.setVisibility(View.INVISIBLE); //causes java.lang.IllegalStateException: Could not execute method of the activity"
TextView HELP0 = (TextView) dialogView.findViewById(R.id.HELP0);
HELP0.setVisibility(View.INVISIBLE); // this works
}
alertdiag_layout.xml:
<View style="@style/Divider1"
android:layout_below="@+id/HELP3"
android:background="#000000"
android:layout_alignRight="@+id/HELP_FIX_LINE"
android:layout_alignLeft="@+id/HELP3"
/>
<TextView
android:id="@+id/HELP0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/HELP_FIX_LINE"
android:textStyle="bold"
android:typeface="normal"
/>
styles.xml:
<style name="Divider1">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
</style>
Sie versuchen, die Sichtbarkeit auf einen Style (R.style.Divider1) einzustellen. Fügen Sie Ihrer Ansicht eine ID hinzu und ändern Sie R.style.Divider1 in R.id.yourNewId –
PERFECT! das funktioniert, DANKE! – juraset
Ich machte es als eine Antwort für Sie zu akzeptieren –