J'essaie de cacher une linearlayout sur un clic de bouton et d'afficher une autre linearlayout qui est dans le même fichier de mise en page. Mais les linearlayouts sont null à l'intérieur du onclick du bouton. Les numéros displayLayout
et editLayout
sont null.LinearLayout est null à l'intérieur du bouton onClick
displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
displayLayout.setVisibility(View.GONE); //error occurs here
editLayout.setVisibility(View.VISIBLE);
}
});
}
Voici le fichier de mise en page:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.prematixsofs.taxiapp.EditUserDetails">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
<!--Display UserDetails Layout-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/displayLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<TextView
android:id="@+id/phNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<TextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/custom_edittext"
android:gravity="center"
android:inputType="textEmailAddress"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<Button
android:id="@+id/edit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/button_custom"
android:text="Edit"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<!--Edit Layout -->
<LinearLayout
android:id="@+id/editLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="@+id/editPhNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="@+id/editPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="@+id/editConfirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
</LinearLayout>
Salut. Merci beaucoup. J'ai changé l'identifiant, mais je l'ai oublié et je ne sais pas pourquoi Android Studio l'a suggéré en tapant même si j'ai supprimé cet identifiant. Merci pour ton aide – Abhi