Remove unnecessary space from AlertDialog - android

I have an AlertDialog that I set a custom view to. In Android Studio's layout preview it shows what I expect the layout to look like:
However when the app runs on my Nexus 6P it looks like this (Note the extra space at the top, that is what I do not want):
As suggested here I tried changing how the layout was set to:
alertDialog2.setView(view2,0,0,0,0);
alertDialog2.show();
However this did not solve my problem. Any suggestions for how to accomplish this?
XML Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:text="Suggest improvements or changes, or report bugs."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:id="#+id/textView5"
android:textColor="#color/Black"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp">
<EditText
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/email_feedback_text"
android:layout_marginLeft="125dp"
android:layout_width="250dp"
android:layout_alignParentBottom="false"
android:layout_marginRight="5dp" />
<TextView
android:text="E-mail*:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:id="#+id/textV5"
android:textColor="#color/Black"
android:layout_alignParentLeft="true"
android:layout_marginLeft="30dp" />
</RelativeLayout>
</RelativeLayout>
Java:
AlertDialog.Builder alertDialogBuilderComplete = new AlertDialog.Builder(
MainActivity.this);
alertDialogBuilderComplete.setCancelable(false);
alertDialogBuilderComplete.setTitle("Submit Feedback"); //Set the title of the box
alertDialogBuilderComplete.setMessage("");
alertDialogBuilderComplete.setNegativeButton("Submit",null);
alertDialogBuilderComplete.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel(); //when they click dismiss we will dismiss the box
}
});
alertDialog2 = alertDialogBuilderComplete.create(); //create the box
alertDialog2.setOnShowListener(new DialogInterface.OnShowListener(){
#Override
public void onShow(DialogInterface dialog) {
Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
button.setOnClickListener(new View.OnClickListener() {
}
});
}
});
alertDialog2.setView(view2,0,0,0,0);
alertDialog2.show();

Remove this line:
alertDialogBuilderComplete.setMessage("")
Or change it to:
alertDialogBuilderComplete.setMessage(null)

After you posted your xml, I see android:layout_marginTop="20dp" make it android:layout_marginTop="0dp"
<TextView
android:text="Suggest improvements or changes, or report bugs."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:id="#+id/textView5"
android:textColor="#color/Black"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:text="Suggest improvements or changes, or report bugs."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
// remove margin top
android:id="#+id/textView5"
android:textColor="#color/Black"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
........
.......
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
// remove margin top, can be added margin as needed
<EditText
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/email_feedback_text"
android:layout_marginLeft="125dp"
android:layout_width="250dp"
android:layout_alignParentBottom="false"
android:layout_marginRight="5dp" />
......
..........
</RelativeLayout>

Related

Instagram options menu from bottom

In the current version of instagram app (Todays date 24-06-2021) ,inside the profile activity/fragment when hamburgur button is pressed (or simply the 3 line icon) now a menu pops up from bottom and can be scroll down by swipe down ,previously when cliked it opens a new fragment/activity
im in love with this animation or a view and im despirat to implement it in my app
but the problem is i dont know what it is called
i want to know what it is exactly and also similar kind of animation or a view is also there in pintrest app
Screen Shot
Update 1
how can i navigate to a fragment from a bottom sheet for eg if in my bootomsheet there is 3 textview i want that if any textView is cliked it should open the respected new fragment i.e if a editprofle textView is clicked it open the editprofile fragment this is how my bottomsheet opens up
Profile_Fragment.java
accountSettings the imageView when clicked the bottomSheetopens up
accountSettings.setOnClickListener(
v -> {
BottomSheet bottomSheet = new BottomSheet();
bottomSheet.show(requireActivity().getSupportFragmentManager(), bottomSheet.get Tag());
}
);
bottom_sheet_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/slidedownview"
android:layout_width="40dp"
android:layout_height="3dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="#drawable/rounded_corner_bottomsheetline"
android:layout_marginTop="11dp"/>
<TextView
android:id="#+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/slidedownview"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:elevation="10dp"
android:text="#string/settings"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="#+id/edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/settings"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:elevation="10dp"
android:text="#string/edit_profile"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="#+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edit_profile"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:elevation="10dp"
android:text="#string/favorite"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="#+id/log_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/favorite"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:layout_marginBottom="15dp"
android:elevation="10dp"
android:text="#string/log_out"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
</RelativeLayout>
Include the following library in your app.gradle file.
implementation 'com.google.android.material:material:<version>'
create custom layout bottom_sheet_dialog_layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:drawableStart="#drawable/ic_settings"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Archive"
android:drawableStart="#drawable/ic_archive"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Activity"
android:drawableStart="#drawable/ic_activity"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
....
....
....
in Class file
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(R.layout.activity_sof);
TextView settings = bottomSheetDialog.findViewById(R.id.settings);
TextView archive = bottomSheetDialog.findViewById(R.id.archive);
TextView your_activity = bottomSheetDialog.findViewById(R.id.activity);
...
...
...
bottomSheetDialog.show();
If you want to click event
settings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Copy is Clicked ", Toast.LENGTH_LONG).show();
bottomSheetDialog.dismiss();
}
});

How to set popup window style for responsive UI in android

In My android app, I used popup window.
There is one issue regarding popup window.
In bigger device (height or width) It will show clearly and automatically set margin left or right.
In smaller device like nexus one , Popup window stick with device not set margin left or right.
Or another issue is that In lollipop or marshmallow there is one button look like floating button. You can view in screen shot which I attached below.
That button look good in marshmallow or higher version.
But in kitkat there is only look like a simple arrow how to resolved it.
Here i specified My popup window source code or screenshots of kitkat device UI and Marshmallow UI.
please any one let me know how to resolved it. In advance, Thank you for your support.
raw_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/demo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:orientation="horizontal"
android:padding="16dp">
<TextView
android:id="#+id/txtMainHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:text="#string/headertext"
android:textColor="#color/colorBlack"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:padding="10dp"
android:text="#string/popupsubtext"
android:textColor="#color/colorBlack" />
<View
android:id="#+id/viewMain"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/txtText"
android:background="#color/bg_border" />
<View
android:id="#+id/view"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="#+id/LayoutDetail"
android:layout_marginLeft="95dp"
android:layout_marginRight="10dp"
android:background="#color/bg_border" />
<LinearLayout
android:id="#+id/LayoutDetail1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/view"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtLastNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/puplastname"
android:textColor="#color/colorBlack"
android:textSize="15sp" />
<TextView
android:id="#+id/txtLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:focusableInTouchMode="true"
android:text="#string/txtLastnametext"
android:textColor="#color/button_text_dialog"
android:textSize="16sp" />
</LinearLayout>
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="#+id/LayoutDetail1"
android:layout_marginLeft="95dp"
android:layout_marginRight="10dp"
android:background="#color/bg_border" />
<LinearLayout
android:id="#+id/LayoutDetail2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/view1"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtEmailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/pupEmail"
android:textColor="#color/colorBlack"
android:textSize="15sp" />
<TextView
android:id="#+id/txtEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/txtemailtext"
android:textColor="#color/button_text_dialog"
android:textSize="16sp" />
</LinearLayout>
<View
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="#+id/LayoutDetail2"
android:layout_marginBottom="10dp"
android:layout_marginLeft="70dp"
android:layout_marginRight="10dp"
android:background="#color/bg_border" />
<ImageView
android:id="#+id/btnNext"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/LayoutDetail2"
android:layout_margin="#dimen/fab_margin"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="14dp"
android:background="#drawable/shape_oval"
android:elevation="2dp"
android:scaleType="center"
android:src="#drawable/ic_icon_right_1" />
<LinearLayout
android:id="#+id/LayoutDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtText"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtFirstNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/pupfirstname"
android:textColor="#color/colorBlack"
android:textSize="15sp" />
<TextView
android:id="#+id/txtFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:focusableInTouchMode="true"
android:text="#string/txtFirstnametext"
android:textColor="#color/button_text_dialog"
android:textSize="16sp" />
</LinearLayout>
Popupwindow.java
private Context mContext;
private Activity mActivity;
private android.widget.PopupWindow mPopupWindow;
private RelativeLayout mRelativeLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_countrycode);
mContext = getApplicationContext();
// Get the activity
mActivity = CountrycodeActivity.this;
// Get the widgets reference from XML layout
mRelativeLayout = (RelativeLayout) findViewById(R.id.mRelativeLayout);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
// Inflate the custom layout/view
View customView = inflater.inflate(R.layout.raw_layout, null);
mPopupWindow = new android.widget.PopupWindow(
customView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
// mPopupWindow.setContentView(findViewById(R.id.activity_view_pager));
mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
if (Build.VERSION.SDK_INT >= 21) {
mPopupWindow.setElevation(24f);
}
new Handler().postDelayed(new Runnable() {
public void run() {
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER, 0, 0);
}
}, 100L);
}
#Override
protected void onStop() {
super.onStop();
mPopupWindow.dismiss();
}
Screenshots of UI
In marshmallow as well as bigger device nexus 5.1
In nexus one as well as kitkat device or smaller
android:layout_width="fill_parent"
set RelativeLayout width property fill_parent

Why is my relative layout filling the screen rather than wrapping content when I add an image?

I have a RelativeLayout, we'll call this the 'slider', that I want to overlay on another RelativeLayout (by switching visibility="gone" and "visible") when "Add People" is clicked, but the overlay should only take up as much width of the screen as needed. This layout will then be removed when "Cancel" is clicked. Everything is working fine so far.
RelativeLayout slider;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_people);
RelativeLayout add = (RelativeLayout) findViewById(R.id.add_wrapper);
RelativeLayout cancel = (RelativeLayout) findViewById(R.id.cancel_wrapper);
slider = (RelativeLayout) findViewById(R.id.add_people_slider);
add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
slider.setVisibility(View.VISIBLE);
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
slider.setVisibility(View.GONE);
}
});
}
The issue arises when I try to add another image to the slider. I am adding this just above the #id/cancel_wrapper RelativeLayout in the XML (full XML at bottom).
<ImageView
android:id="#+id/transparent_add"
android:src="#drawable/ic_add_active_256"
android:layout_height="30dp"
android:layout_width="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
For some reason, this is making the width of the slider the full width of the screen.
What's even more bizarre is if I add android:layout_marginRight="50dp" to this ImageView to move it left a little it starts making the slider smaller from the left. I would like this "transparent_add" image to be lined up with the old "add" image.
My 2 issues, then, are that when I add the "transparent_add" image it changes the width of the slider for an unknown reason, and also when I add marginRight on the image it makes the width of the slider smaller from the left.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<TextView
android:id="#+id/btn_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="10dp"
android:text="#string/label_people"
android:textColor="#color/blue"
android:textSize="16dp" />
<TextView
android:id="#+id/people_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/btn_people"
android:paddingLeft="10dp"
android:text="#string/label_people_info"
android:textSize="11dp" />
<RelativeLayout
android:id="#+id/add_wrapper"
android:layout_width="65dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/blue" >
<ImageView
android:id="#+id/plus_sign"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="19dp"
android:layout_marginTop="6dp"
android:src="#drawable/ic_add_256" />
<TextView
android:id="#+id/add_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="2dp"
android:text="#string/label_add_people"
android:textColor="#color/white"
android:textSize="11dp" />
</RelativeLayout>
<ListView
android:id="#+id/contacts_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="#id/people_info" />
<!-- switch between visible/gone -->
<RelativeLayout
android:id="#+id/add_people_slider"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:background="#color/blue"
android:visibility="gone" >
<TextView
android:id="#+id/label_add_new_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="65dp"
android:layout_alignParentTop="true"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:text="#string/label_add_new_contact"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/label_add_from_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/label_add_new_contact"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="#string/label_add_from_phone"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/label_add_from_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/label_add_from_phone"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="#string/label_add_from_facebook"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/label_add_from_linkedin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/label_add_from_facebook"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="#string/label_add_from_linkedin"
android:textColor="#color/white"
android:textSize="16dp" />
<!-- insert image here -->
<RelativeLayout
android:id="#+id/cancel_wrapper"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="10dp" >
<ImageView
android:id="#+id/image_cancel"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:src="#drawable/ic_close_256"/>
<TextView
android:id="#+id/label_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/label_cancel"
android:textColor="#color/white"
android:textSize="8dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
EDIT: This is happening both in Eclipse and on my Android device.
EDIT: I have tried placing the image above the "Add a new contact" text and then placing the text below that, but the same thing happens

Characters in TextView not displayed properly while typing

I made a TextView and a button. Clicking on the button will save the value entered by the user in a variable. The problem is, when the keyboard pops up after touching the textview, only the first character will be visible properly. The rest of the characters aren't displayed. An _ appears instead of the other characters. After i'm done typing and press the back button and when the keyboard disappears, I can see the characters properly. What is the problem?
Button okbutton = (Button) findViewById(R.id.okbutton);
okbutton.setClickable(true);
final TextView radius = (TextView) findViewById(R.id.radius);
okbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
i=radius.getText().toString();
}
});
Here is the complete layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="#+id/icon" android:src="#drawable/settings"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="10px"></ImageView>
<TextView android:textSize="20px" android:typeface="sans"
android:layout_height="wrap_content" android:id="#+id/alarmset"
android:layout_width="fill_parent" android:text="#string/alarmset"
android:textStyle="bold" android:gravity="center"
android:drawablePadding="10px" android:paddingTop="10px"></TextView>
<TextView android:text="#string/distance" android:id="#+id/distance"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="#+id/alarmset"></TextView>
<TextView android:id="#+id/kmvalue" android:layout_below="#+id/distance"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="#string/km" android:id="#+id/km"
android:layout_below="#+id/distance" android:layout_toRightOf="#+id/kmvalue"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="10px"></TextView>
<TextView android:text="#string/musichooser" android:id="#+id/musictext"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="#+id/km" android:paddingTop="10px"></TextView>
<Button android:id="#+id/chooser" android:layout_below="#+id/musictext"
android:drawableRight="#drawable/lov_ena"
android:layout_alignParentRight="true" android:layout_width="wrap_content"
android:layout_height="30px" android:layout_alignBaseline="#+id/musicfile">
</Button>
<EditText android:id="#+id/musicfile" android:layout_width="fill_parent"
android:layout_below="#+id/musictext" android:layout_toLeftOf="#id/chooser"
android:layout_height="40px">
</EditText>
<TextView android:text="#string/imgchooser" android:id="#+id/imgText"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="#+id/chooser" android:paddingTop="20px"></TextView>
<Button android:id="#+id/imgPicker" android:layout_below="#+id/imgText"
android:drawableRight="#drawable/lov_ena"
android:layout_alignParentRight="true" android:layout_width="wrap_content"
android:layout_height="30px" android:layout_alignBaseline="#+id/imgfile">
</Button>
<EditText android:id="#+id/imgfile" android:layout_width="fill_parent"
android:layout_below="#+id/imgText" android:layout_toLeftOf="#id/chooser"
android:layout_height="40px">
</EditText>
<RelativeLayout android:id="#+id/InnerRelativeLayout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_centerInParent="true">
<Button android:layout_width="wrap_content"
android:layout_height="50px" android:id="#+id/setalarm"
android:layout_centerInParent="true" android:text="#string/setalarm" />
</RelativeLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imgfile"
android:text="Enter Distance" />
<Button
android:id="#+id/okbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="OK" />
<EditText
android:id="#+id/radius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/imgfile"
android:layout_alignTop="#+id/okbutton" />
</RelativeLayout>
This image should make the problem easy to understand
http://i39.tinypic.com/r8t64l.jpg
Try to change the TextView in your Code to EditText.
Button okbutton = (Button) findViewById(R.id.okbutton);
okbutton.setClickable(true);
EditText radius = (EditText) findViewById(R.id.radius);
okbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
i=radius.getText().toString();
}
});
try this....
by mistake you have puted any other view over your edit-text; jus go to your xml file and open Graphical layout, then find that view using mouse-pointer by clicking on that part in which your can not see the text in your shown picture, by double-clicking on that part you can goto xml, and jus remove that view from your xml

Visibility of TextView in Dialog

I have a dialog, which is created with this code:
final Dialog dialog1 = new Dialog(Test.this);
dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog1.setContentView(R.layout.test_layout);
dialog1.setCancelable(true);
...
The layout file 'test_layout.xml' contains a typical TextView:
<TextView
android:id="#+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Test" />
I want in the code to set this TextView invisible (gone) in some cases.
I tried following:
TextView tv = (TextView) dialog1.findViewById(R.id.tv_username);
tv.setVisibility(TextView.GONE);
But the TextView still appears in the dialog. If I set in the layout xml file android:visibility="gone" it is not appearing in the dialog. But I need to do it via code.
Here the whole code:
if (whichButton == 1) {
final Dialog dialog1 = new Dialog(Test.this);
dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog1.setContentView(R.layout.test_layout);
dialog1.setCancelable(true);
TextView tv = (TextView) dialog1.findViewById(R.id.tv_username);
tv.setVisibility(View.GONE);
...
dialog1.show();
}
Here the whole XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="250dp"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/tv_name"
android:paddingTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:textSize="14dp"
android:text="Name:" />
<EditText
android:id="#+id/username"
android:hint="#string/enterName"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:maxLength="15"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:scrollHorizontally="true"
android:capitalize="words"
android:singleLine="true"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Test" />
<TextView
android:id="#+id/tv_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:textSize="14dp"
android:text="#string/message" />
<EditText
android:id="#+id/tip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:maxLength="290"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:scrollbars="vertical"
android:inputType="textMultiLine"
android:capitalize="words"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/button"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/send_message" />
</LinearLayout>
Try tv.setVisibility(View.INVISIBLE);
I found a solution or workaround.
The dialog was created in the the onClick method of an AlertDialog.
Now I use the showDialog() method and handle it in the corresponding callback method.
There it is working fine.
I do not understand why this is working, but I only want to tell other users how they can solve this issue.
I would be happy if someone can come up with a clarification.

Categories

Resources