Hi all i have updated my post to show the full xml file, which will show if i am doing something wrong.
i implemented a custom dialog with an edit text field and it keeps crashing. I will
also like to access the values filled in the text field. Any idea where i am going wrong? Thanks.
Below is the offending/troublesome??? code
First i show the xml file which contains my layout for the alert dialog.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="wrap_content" android:layout_below="#+id/ImageView01"
android:layout_height="200px">
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText
android:id="#+id/lastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="blah"
/>
</ScrollView>
<Button android:id="#+id/Button01"
android:layout_below="#id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Cancel" />
</RelativeLayout>
Then main activity file which implements
my button click events...etc.
.......
setContentView(R.layout.main);
//this button will show the dialog
Button button1main = (Button) findViewById(R.id.Button01main);
button1main.setOnClickListener(new View.OnClickListener() {
public void onClick(View OnClickListener) {
//set up dialog
final Dialog dialog = new Dialog(MoredialogActivity.this);
dialog.setContentView(R.layout.maindialog);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText(R.string.lots_of_text);
//set up image view
ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
img.setImageResource(R.drawable.icon);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
//finish();
}
});
dialog.show();
}
});
}
}
You have two items in your ScrollView. According to the doc :
A ScrollView is a FrameLayout, meaning you should place one child in
it containing the entire contents to scroll; this child may itself be
a layout manager with a complex hierarchy of objects.
So you should had another layout, like a linear layout :
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_below="#+id/ImageView01"
android:layout_height="200px">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:text="#+id/TextView01"
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/lastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="blah" />
</LinearLayout>
</ScrollView>
Related
I have a dialog with custom layout, everything is working fine, except there is a big empty spaces at the top which i cannot remove.
Any suggestion how i can remove that empty space.
Here is my Code:
final Dialog dialog = new Dialog(ConferenceDetailsActivity.this);
dialog.setContentView(R.layout.l_custom_dialog_name);
final CustomEditText nameText = (CustomEditText) dialog.findViewById(R.id.confNameFld);
nameText.setText(mConferenceDetails.getConferenceName());
Button button = (Button) dialog.findViewById(R.id.dialogButtonOK);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final CustomEditText nameText = (CustomEditText) dialog.findViewById(R.id.confNameFld);
String text = nameText.getText().toString();
dialog.dismiss();
}
});
dialog.show();
My xml Layout:
<?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">
<ImageView
android:id="#+id/nameBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/name_badge"
android:layout_alignParentTop="true" />
<com.invosys.iconference.CustomControls.CustomEditText
android:id="#+id/confNameFld"
android:layout_height="45dp"
android:layout_width="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginBottom="20dp"
android:layout_alignTop="#+id/nameBackground"
android:layout_alignBottom="#+id/nameBackground"
android:layout_alignLeft="#+id/nameBackground"
android:layout_alignRight="#+id/nameBackground"
android:background="#null"
android:ems="10"
android:hint="#string/namePlaceholder"
android:gravity="center"
android:isScrollContainer="false"
android:inputType="textFilter|textNoSuggestions"
android:textColor="#color/ECharcoalColor" />
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_below="#+id/nameBackground"
android:layout_alignLeft="#+id/nameBackground"
android:layout_alignRight="#+id/nameBackground" />
..........................
After i used this piece of code the size is reduced but it is still not unto the task;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before setContentView
dialog.setContentView(R.layout.logindialog);
You can try this:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before setContentView
dialog.setContentView(R.layout.logindialog);
How to put close button at top corner in alert dialog box for android?
put close button at right side top corner in alert dialog.
i have used below code for scroll and dialog box
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<ImageVieandroid:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="200dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</ScrollView>
in java coding i have used below coding
i want to put a image to close the dialog box
please help
public void onClick(View v)
{
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.How_to_use:
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.description);
dialog.setTitle("How to use");
TextView text = (TextView) dialog.findViewById(R.id.description);
text.setText(R.string.Descr_How_to_use);
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
image.setOnClickListener(new OnClickListener()
{
// #Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
break;
default:
break;
}
I know, I am late to answer this 2 yrs old question, but this one is for those who don't know a correct approach yet....
Use a Custom Dialog as (everyone has suggested).
Use a RelativeLayout as the main layout of custom_dialog.xml as you will have to float that cancel button on top corner (right/left) of the main window.
custom_dialog.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="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#F4F4F4">
<!--Main Body of your custom dialog-->
</RelativeLayout>
<LinearLayout
android:id="#+id/llTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<ImageButton
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnBookK"
android:background="#null"
android:src="#drawable/ic_close" />
</LinearLayout>
</RelativeLayout>
In your custom dialog code use following line to make it transparent:
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
customDialog.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"
>
<LinearLayout
android:id="#+id/llTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:paddingBottom="10dp"
>
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Close"
/>
</LinearLayout>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_width="130dp"
android:layout_height="130dp"
android:text="Close"
android:layout_centerInParent="true"
android:layout_below="#+id/llTop"
/>
</RelativeLayout>
I have created 1 method whenever you want to display dialog just call this method.
private Dialog dialog; // class variable
private void showDialog
{
dialog = new Dialog(Activity.this); // always give context of activity.
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.customDialog);
Button dialogButton = (Button) dialog.findViewById(R.id.btnClose);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
dialog.dismiss();
}
});
dialog.show();
}
Yo have to create custom dialog
import android.app.Dialog;
import android.content.Context;
public class CustomDialog extends Dialog
{
public CustomDialog(Context context)
{
super(context);
setContentView(R.layout.dialog);
}
}
create dialog.xml file. design according to your requirment.
Is there any similar theme generator as HoloColors or Action Bar Style Generator which would help us change theme of Dialogs and AlertDialogs in our apps?
My app uses Holo theme and I managed to change style of views such as EditTexts and Buttons but they remain unchanged when they appear in a Dialog. I would also like to change color of the blue line under a title.
I've found a few question and answers related to this topic but they practically say it's not even possible. I cannot believe it isn't.
At least for the AlertDialog it is possible. here i posted my solution of a function which is called at some point (for example button click) in your code and creates an alert dialog own layout over your screen.. the layout is a normal layout.xml which you can define the way you want. works perfect for me!
private void showAddUserGeneratedStationDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
AmplifyActivity.this);
LayoutInflater inflater = getLayoutInflater();
//inflate your layout.xml
alertDialog
.setView(inflater.inflate(R.layout.dialog_add_station, null));
//show dialog over activity screen
final AlertDialog ad = alertDialog.show();
//put actions to your ui-elements
Button cancelBtn = (Button) ad
.findViewById(R.id.list_user_generated_cancelBU);
cancelBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ad.cancel();
}
});
Button doneBtn = (Button) ad
.findViewById(R.id.list_user_generated_doneBU);
doneBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//get sth from your layout f.e. some textInput
String stationUrl = ((TextView) ad
.findViewById(R.id.list_user_generated_stationURLInput))
.getText().toString();
// did some other things
ad.dismiss();
}
});
}
and my layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_user_generated_addStationDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99000000"
android:clickable="true"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="300dp"
android:layout_height="200dp"
android:padding="10dp"
android:background="#000"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/list_user_generated_cancelBU"
style="#style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:text="#string/cancel" />
<TextView
style="#style/AmplifyHeadlineElement"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/list_userGenerated_addStation" />
<Button
android:id="#+id/list_user_generated_doneBU"
style="#style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:text="#string/done" />
</LinearLayout>
<EditText
android:id="#+id/list_user_generated_stationURLInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:background="#FFF"
android:ems="10"
android:hint="#string/list_userGenerated_addUrlExample"
android:inputType="textNoSuggestions" >
</EditText>
<!-- MORE BUT I DELETED IT FOR BETTER OVERVIEW -->
</LinearLayout>
</LinearLayout>
I'm using a custom layout for an alert dialog, in which I set a custom background image.
When displayed, it seems that the dialog box is higher than my image background, while I set the layout dimensions to the image dimensions.
How can I set the dialog box dimensions to the dimensions of my background image? How can I remove this white border?
Thanks
dialog layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:orientation="vertical"
android:background="#drawable/whip_sel_dialog_bg"
android:layout_width="279dp"
android:layout_height="130dp" >
<TextView android:id="#+id/dialog_title"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold"
android:text="#string/dialog_title"
android:layout_width="fill_parent" android:gravity="center" android:layout_height="30dp" android:layout_marginTop="5dp"/>
<TextView android:id="#+id/dialog_text"
android:textColor="#FFF"
android:layout_height="35dp" android:layout_width="fill_parent" android:gravity="center"/>
<LinearLayout android:id="#+id/confirmation"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<Button android:id="#+id/button_cancel"
android:layout_width="128dp"
android:layout_height="43dp"
android:background="#drawable/btn_ok"
android:textColor="#FFF"
android:text="#string/cancel"
android:layout_marginRight="10dp"/>
<Button android:id="#+id/button_ok"
android:layout_width="128dp"
android:layout_height="43dp"
android:background="#drawable/btn_ok"
android:textColor="#FFF"
android:text="#string/ok" />
</LinearLayout>
</LinearLayout>
dialog class
public class WSelDialog extends Dialog implements OnClickListener {
private Button okButton, cancelButton;
public WSelDialog() {
super(MainActivity.this);
setContentView(R.layout.whipem_dialog);
okButton = (Button) findViewById(R.id.button_ok);
okButton.setText(getString(R.string.whip_sel_ok));
okButton.setOnClickListener(this);
cancelButton = (Button) findViewById(R.id.button_cancel);
cancelButton.setText(getString(R.string.whip_sel_cancel));
cancelButton.setOnClickListener(this);
TextView text = (TextView) findViewById(R.id.dialog_text);
text.setText(getString(R.string.whip_sel));
text.setOnClickListener(this);
}
#Override
public void onClick(View v) {
((GlobalVars)getApplicationContext()).playSound(100);
if (v == cancelButton)
dismiss();
else {
Intent i = new Intent(MainActivity.this, WhipSelection.class);
startActivity(i);
}
}
};
It looks like the dialog reserves this space for its title. See Android: How to create a Dialog without a title.
I need to put EditText box with vertical scrollbar on custom dialog.i.e when I entered more than one line on edittext, it should be scrolled. Here I used android: scrollable="vertical" on xml.
It works fine. When I use two edittext boxes, the curor will move to second edittext box when I press enter on first. Any mistakes?
My code...
EditText edit1,edit,edit0;
Button ok;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
final Dialog dialog = new Dialog(summaact.this);
dialog.setContentView(R.layout.main);
edit0=(EditText)dialog.findViewById(R.id.edit0);
edit=(EditText)dialog.findViewById(R.id.edit);
edit1=(EditText)dialog.findViewById(R.id.edit1);
edit0.setInputType(InputType.TYPE_NULL);
edit.setInputType(InputType.TYPE_NULL);
edit1.setInputType(InputType.TYPE_NULL);
ok=(Button)dialog.findViewById(R.id.ok);
dialog.setTitle("Content Management page");
dialog.setCancelable(true);
ok.setOnClickListener(new OnClickListener(){
public void onClick(View v){
String str0=edit0.getText().toString();
String str=edit1.getText().toString();
String str1=edit.getText().toString();
Toast.makeText(summaact.this,str0,Toast.LENGTH_SHORT).show();
Toast.makeText(summaact.this,str,Toast.LENGTH_SHORT).show();
Toast.makeText(summaact.this,str1,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
dialog.show();
}
My xml...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/edit0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/edit1"
android:layout_width="fill_parent"
android:layout_height="100px"
android:scrollbars="vertical"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ok"
android:text="OK"/>
</LinearLayout>
new answer:
Try using:
android:inputType="textMultiLine"
in EditText
edit:
I made an example and it works with textMultiline:
#Override
protected void onResume() {
super.onResume();
AlertDialog.Builder b = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.main, null);
b.setView(view);
b.setTitle("Content Management page");
b.create().show();
}
Layout is the same except one EditText:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/edit0"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/edit1"
android:layout_width="fill_parent"
android:gravity="top|left"
android:layout_height="100dp"
android:scrollbars="vertical"
android:inputType="textMultiLine" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ok"
android:text="OK" />
</LinearLayout>
Where did you have problem?
try
YourEditText.setMovementMethod(new ScrollingMovementMethod());
and be sure to set scrollbars true