Я хочу, чтобы пользователь выбирал, хотите ли они сделать снимок или выбрать один из галереи.Почему я не могу получить диалог при нажатии на изображение?
Я установил OnClickListener на свое изображение, но когда я нажимаю изображение, ничего не происходит.
Вот код моего SettingUpUserProfile.java файла:
public class SettingUpUserProfile extends AppCompatActivity {
public static final int TAKE_PHOTO_REQUEST = 0;
protected ImageView userProfilePicture;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting_up_user_profile);
userProfilePicture = (ImageView) findViewById(R.id.userProfilePicture);
userProfilePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(SettingUpUserProfile.this);
builder.setTitle(null);
builder.setItems(R.array.pickImage_options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
switch (position) {
case 0:
Intent intentCaptureFromCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intentCaptureFromCamera, TAKE_PHOTO_REQUEST);
break;
case 1:
// Choose from gallery.
}
}
});
}
});
}
}
и вот код моего activity_setting_up_user_profile.xml файла:
<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:background="@color/light_purple"
tools:context="com.abc.xyz.SettingUpUserProfile">
<TextView
android:id="@+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="@string/settingUpUserProfileText1"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="30sp"
android:gravity="center_horizontal|center_vertical"/>
<ImageView
android:id="@+id/userProfilePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="@drawable/ic_face_white_48dp" />
<TextView
android:id="@+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/userProfilePicture"
android:layout_marginTop="5dp"
android:text="@string/settingUpUserProfileText2"
android:textColor="@color/white"
android:textSize="15sp"
android:gravity="center_horizontal|center_vertical"/>
<EditText
android:id="@+id/userName"
android:background="@drawable/phone_number_edit_text_design"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/settingUpUserProfileText2"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:gravity="center_horizontal|center_vertical"
android:hint="@string/hint_userName"
android:textColor="@color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="@null"
android:inputType="textPersonName"/>
<Button
android:id="@+id/buttonAllSet"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/userName"
android:layout_marginTop="20dp"
android:text="@string/button_allSet"
android:textStyle="bold"
android:textColor="@color/light_purple"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:gravity="center_horizontal|center_vertical"/>
</RelativeLayout>
Я действительно не в состоянии понять, что здесь неправильно.
Просьба, дайте мне знать.
Я новичок в StackOverflow, поэтому, пожалуйста, сотрудничайте.
Заранее спасибо.
builder.show(); –
@ MLProgrammer-CiM ** Awesome **. Извините за такую глупую ошибку! –