Sorry guys, But I am new, This is my homepage java class.
IntroButton is Working well, but Feedback is not working, i am
touching feedback button, but it is untouched. mean no output.
Created by AwaisButt awais.b7solpk#gmail.com on 4/15/2015.
public class HomePage extends Activity { protected void
onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.homepage);
Button introButton = (Button) findViewById(R.id.bIntro);
Button feedBackButton = (Button) findViewById(R.id.bFeedBack);
introButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(HomePage.this,Introduction.class);
startActivity(intent);
}
});
feedBackButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(HomePage.this,FeedBack.class);
startActivity(intent);
}
});
}
XML File
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/homepage">
<Button
android:layout_width="139dp"
android:layout_height="44dp"
android:id="#+id/bIntro"
android:layout_marginLeft="23dp"
android:layout_marginTop="180dp"
android:background="#android:color/transparent"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:background="#android:color/transparent"
android:layout_height="44dp"
android:text="FeedBack"
android:id="#+id/bFeedBack"
android:layout_marginLeft="23dp"
android:visibility="invisible"
android:layout_marginTop="1dp"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:background="#android:color/transparent"
android:layout_height="44dp"
android:visibility="invisible"
android:text="Order"
android:id="#+id/bOrder"
android:layout_marginLeft="23dp"
android:layout_marginTop="-4dp"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:visibility="invisible"
android:layout_height="44dp"
android:text="Catalogue"
android:background="#android:color/transparent"
android:id="#+id/bCatalogue"
android:layout_marginLeft="23dp"
android:layout_marginTop="-7dp"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="139dp"
android:visibility="invisible"
android:layout_height="44dp"
android:text="Web"
android:id="#+id/bWeb"
android:layout_marginLeft="23dp"
android:layout_marginTop="-10dp"
android:background="#android:color/transparent"
android:layout_gravity="center_vertical" /> </LinearLayout>
Mistake:
You did a mistake, visibility of the feedback button is Invisible! Intro button is getting clicked because it's visible in your layout!
FYI
View.GONE This view is invisible, and it doesn't take any space for
layout purposes.
View.INVISIBLE This view is invisible, but it still takes up space for
layout purposes.
Check your OnClickListener() is of type View.OnClickListener().
It's because you set that button as Invisible.
<Button
android:layout_width="139dp"
android:background="#android:color/transparent"
android:layout_height="44dp"
android:text="FeedBack"
android:id="#+id/bFeedBack"
android:layout_marginLeft="23dp"
android:visibility="invisible" // here
android:layout_marginTop="1dp"
android:layout_gravity="center_vertical" />
remove that line. It will work.
One more solution is,
you can use this line in onCreate method after you find the button id.
feedBackButton.setVisibility(View.VISIBLE);
Good luck!
Related
I have a CardView in my Activity which has a close button. when I click on the close button the CardView closes, but when I come back to the activity the CardView shows again.
I want that the CardView doesn't show once I close it until I exit or close the application.
activity_detail.xml
<androidx.cardview.widget.CardView
android:id="#+id/cardview_ad"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
app:cardCornerRadius="12dp"
app:cardElevation="4dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal"
android:paddingHorizontal="9dp"
android:paddingVertical="6dp">
<TextView
android:id="#+id/textview_ad_icon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="#font/fa_solid"
android:padding="3dp"
android:paddingStart="4dp"
android:paddingEnd="0dp"
android:text="#string/fa_bullhorn_ad"
android:textColor="#636363"
android:textSize="19sp" />
<TextView
android:id="#+id/textview_ads"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:fontFamily="#font/google_sans"
android:padding="3dp"
android:paddingStart="1dp"
android:paddingEnd="4dp"
android:text="Ads"
android:textColor="#636363"
android:textSize="18sp" />
<TextView
android:id="#+id/textview_btn_close_ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:fontFamily="#font/fa_solid"
android:gravity="end"
android:padding="2dp"
android:text="#string/fa_times_circle_close"
android:textColor="#79636363"
android:textSize="28sp" />
</LinearLayout>
<View
android:id="#+id/divider_ad"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="44dp"
android:background="?android:attr/listDivider" />
</androidx.cardview.widget.CardView>
DetailActivity.java
public class DetailActivity extends AppCompatActivity {
TextView textViewBtnCloseAd;
CardView cardViewAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
// view reference
textViewBtnCloseAd = findViewById(R.id.textview_btn_close_ad);
cardViewAd = findViewById(R.id.cardview_ad);
// close the ad panel
textViewBtnCloseAd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
cardViewAd.setVisibility(View.GONE);
}
});
}
}
I really appreciate your help.
Thank you!
Try save the close state(a boolean value) in a static variable which can be defined in Application or an util class and set your cardViewAd visibility according to the close state get from the static variable when DetailActivity onCreate. The default state could be true. Once reopen the application, the close state reset to true.
I am currently creating an app on Android Studio.
I use different buttons (in the same activity) that go to different activities. The problem is that, with one button, it all works, but when I add another one the emulator crashes.
Here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
defineButtons();
}
public void defineButtons() {
findViewById(R.id.next1).setOnClickListener(buttonClickListener);
findViewById(R.id.next2).setOnClickListener(buttonClickListener);
findViewById(R.id.next3).setOnClickListener(buttonClickListener);
}
private View.OnClickListener buttonClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.next1:
Intent Next1 = new Intent (Start.this, Next1.class);
startActivity(Next1);
break;
case R.id.next2:
Intent Next2 = new Intent (Start.this, Next2.class);
startActivity(Next2);
break;
case R.id.next3:
Intent Next3 = new Intent (Start.this, Next3.class);
startActivity(Next3);
break;
}
}
};
And here the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Start"
android:background="#drawable/background">
<TextView
android:layout_width="match_parent"
android:layout_height="700px"
android:id="#+id/statement"
android:text="TEXT1"
android:background="#drawable/button_border"
android:textColor="#000000"
android:alpha="0.95"
android:layout_marginHorizontal="70px"
android:layout_marginTop="180px"
android:gravity="center"
android:paddingHorizontal="50px"
android:textSize="16sp"
/>
<Button
android:id="#+id/next1"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="150px"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="160dp"
android:layout_marginHorizontal="70px"
android:alpha="0.9"
android:background="#drawable/button_border"
android:text="TEXT2"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textAllCaps="false"/>
<Button
android:id="#+id/next2"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="150px"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="90dp"
android:layout_marginHorizontal="70px"
android:alpha="0.9"
android:background="#drawable/button_border"
android:text="TEXT3"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textAllCaps="false"/>
<Button
android:id="#+id/next3"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="150px"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginHorizontal="70px"
android:alpha="0.9"
android:background="#drawable/button_border"
android:text="TEXT4"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textAllCaps="false"/>
</RelativeLayout>
I know this is messy, I'm new at programming.
Your code is perfectly fine you just need to declare your Next2, and Next3 activities in manifest file like this
<activity android:name=".Next2"
android:screenOrientation="portrait"/>
<activity android:name=".Next3"
android:screenOrientation="portrait"/>
Android reads your app components from manifest file, refer this link for more details https://developer.android.com/guide/topics/manifest/manifest-intro
EDIT: updated my code , posted more of the code for you to see .
EDIT: why am i being downvoted ?
EDIT2: broke my code lol , im going to reverse all you're suggestions , and try the xml option provided
i would like to know if i can use startActivityForResult in my main activity.
i'm opening a scannerview with the code below ,
what i see as my SECOND activiy .
how could i get that result because it's not officially another activity it's only a method.
Button sendButton;
//EditText edt4;
EditText edt2;
#SuppressLint("CutPasteId")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt4 = findViewById(R.id.editText4);
ZXingScannerView mScannerView = findViewById(xmlScannerView););
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
public void onClick(View v){
ZXingScannerView mScannerView = new ZXingScannerView(this);
mScannerView.setVisibility(View.VISIBLE);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
//EditText editText4;
EditText edt4;
#Override
public void handleResult(final Result result) {
//handle result
Log.v("handleResult", result.getText());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Ordernummer of Locatie");
builder.setMessage(result.getText());
AlertDialog alertDialog = builder.create();
alertDialog.show();
//edt4.setText(result.getText());
//edt4 = findViewById(editText4);
//edt4.setText(String.valueOf(result.getText()));
runOnUiThread(new Runnable() {
#Override
public void run() {
updateScannerData(1,result.getText());
}
});
}
private void updateScannerData(int scanType, String scannedCode){
//startActivity(new Intent(this,MainActivity.class));
//this.finish();
edt4.setText(scannedCode);
}
#Override
public void onBackPressed()
{
startActivity(new Intent(this,MainActivity.class));
this.finish();
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="#mipmap/ic_launcher_foreground">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginTop="67dp"
android:ems="10"
android:hint="#string/scan_locatie"
android:inputType="text"
android:text=""
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="197dp"
android:ems="10"
android:hint="#string/scan_order"
android:inputType=""
android:visibility="visible"
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText2"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<Button
android:id="#+id/sendButton"
android:layout_width="157dp"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="72dp"
android:background="#android:color/holo_red_light"
android:text="#string/button"
tools:text="Versturen.." />
<Button
android:id="#+id/button3"
android:layout_width="40dp"
android:layout_height="38dp"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
<Button
android:id="#+id/button4"
android:layout_width="39dp"
android:layout_height="37dp"
android:layout_alignBaseline="#+id/editText4"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="#+id/xmlScannerView"
android:visibility="gone"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</FrameLayout>
No you can't, either use multiple layout groups in your activity's layout or use multiple fragments.
if you go for the first option, you should add the ZXingScannerView in you XML layout and simple tangle it's visibility if you want to use it
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:width="match_parent"
height="match_parent"
android:id="someId"
android:visibility="gone"
/>
And then in your code
private ZXingScannerView mScannerView;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(someLayout);
mScannerView = findViewById(SomeId);
mScannerView.setFormats(ZXingScannerView.ALL_FORMATS);// dont forget this
mScannerView.setResultHandler(this);
mScannerView.startCamera()
}
public void onClick(View v){
mScannerView.setVisibility(View.Visible);
}
EDIT
Call setFormats see above and start the camera is the onCreate() and change the visibility in the XML to INVISIBLE
EDIT 2
Your XML is supposed to be like this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="#mipmap/ic_launcher_foreground">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="#+id/xmlScannerView"
android:visibility="gone"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<RelativeLayout
android:id="#+id/someId"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginTop="67dp"
android:ems="10"
android:hint="#string/scan_locatie"
android:inputType="text"
android:text=""
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="197dp"
android:ems="10"
android:hint="#string/scan_order"
android:inputType=""
android:visibility="visible"
tools:backgroundTint="#android:color/holo_red_light" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText2"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_red_light"
android:onClick="onClick"
android:text="#string/scan_qr"
tools:text="scan qr code" />
<Button
android:id="#+id/sendButton"
android:layout_width="157dp"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="72dp"
android:background="#android:color/holo_red_light"
android:text="#string/button"
tools:text="Versturen.." />
<Button
android:id="#+id/button3"
android:layout_width="40dp"
android:layout_height="38dp"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
<Button
android:id="#+id/button4"
android:layout_width="39dp"
android:layout_height="37dp"
android:layout_alignBaseline="#+id/editText4"
android:layout_alignParentEnd="true"
android:background="#android:drawable/ic_delete" />
</RelativeLayout>
</FrameLayout>
And then when calling the onClick
public void onClick(View v){
yourRelativeLayout.setVisibility(View.Invisible);
mScannerView.setVisibility(View.Visible);
}
Well, I think we need to take a look at your current code and the ZXingScannerView. If we take a look at the Github repository of the ZXingScannerView, there is an example which differs a bit from your implementation.
First of all, you should call setContentView(mScannerView);, only in your Activity's onCreate() once. Right now, when you click, the entire view gets redrawn, which is not needed. You also set the resultHandler each time when you click on the button, which might cause problems as well.
This code is taken from the Github repo of the element you are using, so please make your Activity look like this.
https://github.com/dm77/barcodescanner
public class SimpleScannerActivity extends Activity implements ZBarScannerView.ResultHandler {
private ZBarScannerView mScannerView;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZBarScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
}
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
#Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v(TAG, rawResult.getContents()); // Prints scan results
Log.v(TAG, rawResult.getBarcodeFormat().getName()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
}
}
Also note that you will need permissions to access the phone's camera.
I would like to ask on how to achieve to wrap a content in alertdialog?
Because the current output of my dialog has an excess white field.
Hope someone can help me to understand this problem thanks.
Here is my activity_dialog.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:minWidth="10dp"
android:minHeight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="com.bloxofcode.toggle.MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="50sp"
android:background="#color/colorHeaderDialog"
android:textColor="#android:color/white"
android:text="#string/select_gender"
android:padding="15dp"
android:gravity="center_horizontal|left"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:padding="15dp"
android:text="Sample"
android:id="#+id/editText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ToggleButton
android:text="ToggleButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toggleButtonMale"
android:textOn=""
android:textOff=""
android:focusable="false"
android:background="#drawable/check_male"
android:layout_weight="1" />
<ToggleButton
android:text="ToggleButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toggleButtonFemale"
android:textOn=""
android:textOff=""
android:focusable="false"
android:background="#drawable/check_male"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<Button
android:id="#+id/btnCancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:textSize="20dp"
android:padding="30dp"
android:textColor="#android:color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btnAccept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accept"
android:textSize="20dp"
android:padding="30dp"
android:background="#color/colorDialogOK"
android:textColor="#android:color/white"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Here is some of my implementation in the MainActivity.java:
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
View mView = getLayoutInflater().inflate(R.layout.activity_dialog, null);
.....
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
dialog.show();
Try Creating a dialog like this. this works perfect and then right away your dialog logic is seperated from you activity logic
public class CustomDialog extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public CustomDialog d;
public Button yes, no;
public CustomDialog(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_layout);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//dosomething
}
});
}
}
Hope it is not correct to wrap the content of dialog as it might disrupt the view in tablets and larger devices.
Anyhow, basing upon your requirement.. hope this link works
AlertDialog with custom view: Resize to wrap the view's content
I want the user to choose that whether they'd like to take picture or choose one from gallery.
I set up an OnClickListener on my Image but when I'm clicking the image, nothing is happening.
Here is my SettingUpUserProfile.java file's code:
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.
}
}
});
}
});
}
}
and here is my activity_setting_up_user_profile.xml file's code:
<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>
I'm really unable to figure out what is wrong here.
Kindly, let me know.
I'm new to StackOverflow so please cooperate.
Thanks in advance.
Add Below lines to your onClick() method
AlertDialog alertDialog = builder.create();
alertDialog.show();