I'm trying to get a custom Dialog to work. It should have no Title, a basic TextMessage and my Custom Layout where normally Buttons appear.
I tried to accomplish this with an AlertDialog.Builder, extending Dialog, call methods on the Dialog and still not get the expected result.
This is the layout, I Like to use as a custom ButtonArea (layout/dialog_footer):
<?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="wrap_content" >
<CheckBox
android:id="#+id/dialog_checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/never_show_again"
android:textColor="#color/black"
android:visibility="gone"
android:background="#color/dialog_button_background"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/dialog_checkbox"
android:layout_alignWithParentIfMissing="true"
android:orientation="horizontal"
android:background="#color/dialog_button_background"
android:paddingBottom="-10dip">
<Button
android:id="#+id/dialog_btn_positive"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="#string/ok"
android:gravity="center"
android:visibility="gone"
/>
<Button
android:id="#+id/dialog_btn_negative"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="#string/btn_cancel"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
The simplest try goes like this:
AlertDialog.Buiilder builder = new AlertDialog.Builder(context);
builder.setMessage("my Message");
Dialog dialog = builder.create();
//builder has `setView for Message or setCustomTitle, but no setCustomFooter
LayoutInflater inflater = LayoutInflater.from(context);
View footer = inflater.inflate(R.layout.dialog_footer);
//either NullPointer Exception
dialog.addContentView(footer, footer.getLayoutParams);
//or AndroidRuntimeException (requestFeature() must be called befoire adding content)
dialog.addContentView(footer, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
If I try to emulate the "MessageArea" by putting a TextView on Top of my Layout it works, but has very ugly black borders at the bottom (I guess its the custom Dialog-Theme).
Whats the best way to keep the "look and feel" of a System Dialog, but replace the Buttons with my own View and handle anything myself?
Hello friend please check this post it may be helpful for your problem
Android - Custom AlertDialog Background Color
Here which i have build my own Custom Edit Dialog for my app see the Layout code
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Name: "
android:textColor="#fff" />
<EditText
android:id="#+id/txtDelName"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp" />
</TableRow>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Contact No :"
android:textColor="#fff" />
<EditText
android:id="#+id/txtDelAge"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:ems="10" >
<requestFocus />
</EditText>
</TableRow>
<TableRow android:layout_height="wrap_content" >
<Spinner
android:id="#+id/spinDiagDept"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_span="2"
android:prompt="#string/Rel_prompt"
android:visibility="visible" />
</TableRow>
</TableLayout>
And here is the alert dialog code
public class Alerts {
public static AlertDialog ShowEditDialog(final Context con,final Emergencydb emp)
{
AlertDialog.Builder b=new AlertDialog.Builder(con);
b.setTitle("Emergency Contact Details");
LayoutInflater li=LayoutInflater.from(con);
View v=li.inflate(R.layout.editdialog, null);
b.setIcon(android.R.drawable.ic_input_get);
b.setView(v);
final TextView txtName=(TextView)v.findViewById(R.id.txtDelName);
final TextView txtAge=(TextView)v.findViewById(R.id.txtDelAge);
final Spinner spin=(Spinner)v.findViewById(R.id.spinDiagDept);
Utilities.ManageDeptSpinner(con, spin);
for(int i=0;i<spin.getCount();i++)
{
long id=spin.getItemIdAtPosition(i);
if(id==emp.getDept())
{
spin.setSelection(i, true);
break;
}
}
txtName.setText(emp.getName());
txtAge.setText(String.valueOf(emp.getAge()));
b.setPositiveButton("Modify", new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
emp.setName(txtName.getText().toString());
emp.setAge(String.valueOf(txtAge.getText().toString())); emp.setDept((int)spin.getItemIdAtPosition(spin.getSelectedItemPosition()));
try
{
#SuppressWarnings("rawtypes")
DatabaseHelper db=new DatabaseHelper(con);
db.UpdateEmp(emp);
Toast.makeText(getBaseContext(), "Modified Successfully", Toast.LENGTH_SHORT).show();
}
catch(Exception ex)
{
}
}
});
b.setNeutralButton("Delete", new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
#SuppressWarnings("rawtypes")
DatabaseHelper db=new DatabaseHelper(con);
db.DeleteEmp(emp);
}
});
b.setNegativeButton("Cancel", null);
return b.create();
//diag.show();
}
protected static Context getBaseContext() {
// TODO Auto-generated method stub
return null;
}
public static void ShowEmpAddedAlert(
android.view.View.OnClickListener onClickListener) {
// TODO Auto-generated method stub
}
}
with the help of Aleks G I managed to get it work:
the code flow goes like this:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("MyMessage");
LayoutInflater inflater = LayoutInflater.from(context);
View footerView = inflater.inflate(R.layout.apo_plus_dialog_footer, null);
AlertDialog alertDialog = builder.create();
alertDialog.setView(footerView, 0,0,0,0);
if (!hasTitle){
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
alertDialog.show();
just in case someone wants to have a similar Dialog behavior than me.
Related
I'm working on android project. I want to show a popup dialog inside my activity. I have implemented it (All the codes attached below). But my question is, when I run this project in android the popup shows like this. I need to increase the width of this popup dialog. I tried a few solutions, but didn't work for me. Please help me to solve this matter. Thanks in advance.
Here is my code
xml file--
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/lv_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="MSGP3006"
android:textColor="#color/Black"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QTY:2 | Weight : 500g | Discount::25%"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_marginBottom="#dimen/dimen_5dp"
android:layout_gravity="bottom">
<TextView
android:id="#+id/amount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Rs.360.00"
android:gravity="end"
android:textColor="#color/Sky_Dark_Blue"
android:textSize="22sp"/>
</LinearLayout>
</LinearLayout>
java file--
public class AddInvoiceDialog extends Dialog {
public Activity activity;
public Dialog dialog;
public Button btn_add;
public AddInvoiceDialog(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.activity = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.inv_add_new_invoice_popup);
btn_add = (Button) findViewById(R.id.btn_add);
btn_add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
activity.finish();
}
});
}
}
Add below line after setContentView(R.layout.inv_add_new_invoice_popup);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
You will get popup window matching device width.
You also need to add android:orientation="vertical" in your parent LinearLayout, it contains multiple child.
You can set custom view in Alert Dialog as mentioned below :
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout.inv_add_new_invoice_popup, null);
alertDialog.setView(dialogView);
alertDialog.setCancelable(false);
alertDialog.show();
Somehow the scroll view is not working . The message alert dialog box is showing is really big and so I need to implement vertical scrollbar. I tried to get data from previous asked question but it isn't solving my issue please help.
I need to show the alert dialog on button click event.
benefits.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog ad = new AlertDialog.Builder(Panchgavya.this).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage(getString(R.string.benefits));
ad.setTitle("Benefits");
ad.setButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
ad.show();
TextView textView = (TextView) ad.findViewById(android.R.id.message);
textView.setScroller(new Scroller(Panchgavya.this));
textView.setVerticalScrollBarEnabled(true);
textView.setMovementMethod(new ScrollingMovementMethod());
}
});
My XML File Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Design.Panchgavya"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/Green"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Panchgavya"
android:textColor="#color/white"/>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:orientation="vertical">
<TextView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:text="#string/panchgavya"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="#+id/panchgavya_tv_cow_dung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cow Dung"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textStyle="bold"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_cow_urine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Cow Urine"
android:textStyle="bold"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_cow_milk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Cow Milk"
android:textStyle="bold"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_ghee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:text="Ghee"
android:textStyle="bold"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_dahi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:text="Dahi"
android:textStyle="bold"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<Button
android:id="#+id/panchgavya_btn_benefits"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Benefits"
android:background="#color/Green"
android:textColor="#color/white"
/>
</LinearLayout>
</LinearLayout>
You can create custom layout for your dialog and set any property easily.
For your requirement, Crate a layout for your required Dialog. Put android:scrollbars = "vertical" in your textView inside your layout. And textview.setMovementMethod(new ScrollingMovementMethod());.
You can set custom layout on your by following method.
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Textview
android:id="#+id/txtDescription"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/margin_16dp"
android:paddingRight="#dimen/margin_16dp"
android:paddingBottom="#dimen/margin_16dp"
android:paddingTop="#dimen/margin_10dp"
android:text="#string/dummy_text_"
android:textSize="#dimen/font_14dp"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/imgClose"/>
<ImageView
android:id="#+id/imgClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_close"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_10dp"
android:layout_marginTop="#dimen/margin_10dp" />
</RelativeLayout>
</ScrollView>
// in your java file put below code
private void showPopup() {
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.dialog_terms_services,
null);
dialogBuilder.setView(dialogView);
TextView txtDescription = dialogView.findViewById(R.id.txtDescription);
ImageView imgClose = dialogView.findViewById(R.id.imgClose);
txtDescription.setText(message);
final AlertDialog b = dialogBuilder.create();
b.show();
imgClose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
b.dismiss();
}
});
}
// after than call that showPopup() methos on button click.Hope it works for you
class extending DialogFragment can have UI elements as per your requirement.
public class OrderDetailFragment extends DialogFragment{
#Override
public void onStart() {
super.onStart();
Dialog d = getDialog();
if (d!=null){
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.WRAP_CONTENT;
d.getWindow().setLayout(width, height);
}
}
public static OrderDetailFragment getInstance(GeneralListDataPojo dataList){
OrderDetailFragment orderDetailFragment=new OrderDetailFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(DATA, dataList);
orderDetailFragment.setArguments(bundle);
return orderDetailFragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root_view = inflater.inflate(R.layout.fragment_order_detail, container, false);
GeneralListDataPojo mDataList = getArguments().getParcelable(DATA);//My class which holds data implemented Parcelable
//population of data from mDataList
return root_view;
}
void closeDialog(){
this.dismiss();
}
}
fragment_order_detail is having my requirement specific element's (ScrollView/LinearLayouts/Buttons etc)
GeneralListDataPojo is the class which holds data implements Parcelable for transferring data between components
Now you can invoke this DialogFragment from your Fragment like this. (Im invoking from a Fragment. Change the FragmentManager retrieval accordingly if you are using from Activity)
OrderDetailFragment orderDetailFragment=OrderDetailFragment.getInstance((GeneralListDataPojo) responseObj);
FragmentManager fragmentManager=getFragmentManager();
orderDetailFragment.show(fragmentManager,"OrderDetailFragment");
Create The Custom Dialog layout Using Scroll View in your own custom Layout
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Dialog dialog= new Dialog(getApplicationContext());
dialog.setContentView(R.layout.activity_dialog);
Button click= dialog.findViewById(R.id.click);
click.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
I had problems with this when I was programming it. I thought I'd cured it by specifying a fixed percentage height for the body of the dialog. I thought this was bad form, because the user might have a slim display, or set large fonts, which would cut of the EditText box.
Anyway that solution has failed beyond the emulator.
It looks like Android is assigning a fixed height to a dialog, and if my custom title has devoured too much of this height, squeezing everything else off. Is this correct and how do I fix it?
Problem
public class GetUserNameDialogFragment extends DialogFragment {
final String TAG = "GetUserNameDialog";
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle);
//TODO getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
LayoutInflater inflater = getActivity().getLayoutInflater();
final View sunburst =inflater.inflate(R.layout.dialog_user_name, null);
builder.setView(sunburst);
builder.setCancelable(false)
.setPositiveButton("Let's go!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.wtf(TAG, "button press");
EditText name = (EditText) sunburst.findViewById(R.id.nameEditText);
String userName = name.getText().toString().trim();
//TODO needs to be validated
SharedPreferences sharedPref = getActivity().getSharedPreferences("userDetails", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("userName", userName );
editor.commit();
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
Here's the xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="#drawable/ic_ball_sunburst_classic"
android:background="#color/colorAccent"
/>
<LinearLayout
android:layout_width="250dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_height="125dp">
<EditText
android:id="#+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:hint="Enter your first name"/>
</LinearLayout>
</LinearLayout>
All help very much appreciated, the first impression of my app - what a disaster!
Why don't you use Dialog instead of AlertDialog ?
I built the example using a Dialog and it works perfectly
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:layout_width=" 290dp"
android:layout_height="wrap_content"
android:background="#4CAF50">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/base"
android:background="#color/colorAccent"
/>
<EditText
android:textColor="#fff"
android:textColorHint="#fff"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:id="#+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your first name"/>
<Button
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:id="#+id/letsGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Let's Go"
android:textColor="#fff"
android:background="#android:color/transparent"/>
final Dialog dialog = new Dialog(context);
if(dialog.getWindow() != null){
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
dialog.setContentView(R.layout.dialog);
Button letsGO = (Button) dialog.findViewById(R.id.letsGo);
EditText nameEditText = (EditText) dialog.findViewById(R.id.nameEditText);
letsGO.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "Lets GO!", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
dialog.show();
I need some help.I'm using this EnhanceListView for swipe to dismiss in my alertDialog but the swipe is not working. Does the swipe to dismiss doesn't work on alertdialog? or Am i missing something.? I tried setting the directions but still not working.
here is my code
public void viewDataList() {
LayoutInflater inflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.alert_opendata, null);
lv = (EnhancedListView) view
.findViewById(R.id.data_list);
TextView emptyText = (TextView) view.findViewById(android.R.id.empty);
lv.setEmptyView(emptyText);
DisplayDataAdapter adapter = displayData();
lv.setAdapter(adapter);
lv.setDismissCallback(new OnDismissCallback() {
#Override
public Undoable onDismiss(EnhancedListView arg0, int arg1) {
// TODO Auto-generated method stub
return null;
}
});
lv.setSwipingLayout(R.id.swiping_layout);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setView(view);
builder.setNegativeButton("Close",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
return;
}
});
builder.create().show();
}
my xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<de.timroes.android.listview.EnhancedListView
android:id="#+id/data_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C0C0C0"
android:minHeight="30dp" >
</de.timroes.android.listview.EnhancedListView>
<TextView
android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="No Data"
android:textSize="20sp" />
</LinearLayout>
my List Item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swiping_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:background="#F8f8f8"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/datalist_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F8f8f8"
android:padding="10dp"
android:textSize="20sp" >
</TextView>
</LinearLayout>
i don't see you setting anywhere lv.enableSwipeToDismiss();
also, you may want to add stuff like:
lv.setUndoStyle(EnhancedListView.UndoStyle.MULTILEVEL_POPUP);
lv.setSwipeDirection(EnhancedListView.SwipeDirection.BOTH);
Good evening, programmers. I have a problem. Please help me to solve it.
I am writing an android application. I can't create custom dialogs. I have errors or my application looks very awfully. I have some dialogs in my application. Here is of a part of my programm:
The view is very terrible, isn't it? I want that one of the layouts to be in the dialog but it appears in the main activity. Why?
dialogtable.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout01"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<LinearLayout
android:id="#+id/LinearLayout02"
android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<TextView
android:id="#+id/textRows"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Amount of rows "/>
<TextView
android:id="#+id/textColumns"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Amount of columns"/>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout03"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
>
<EditText
android:id="#+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:inputType="number"
android:gravity="right"/>
<EditText
android:id="#+id/EditText02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"/>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout04"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
>
<TextView
android:id="#+id/textBorder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Width of border"/>
<EditText
android:id="#+id/EditText03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"/>
</LinearLayout>
</LinearLayout>
The code from MainActivity
#Override
protected Dialog onCreateDialog(int id) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialogtable, (ViewGroup)findViewById(R.id.LinearLayout01));
AlertDialog.Builder alert = null;
alert = new AlertDialog.Builder(this);
alert.setView(layout);
alert.setTitle("Create table");
alert.setCancelable(false);
alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alert.setPositiveButton("OK",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Editable rows = fieldForRows.getText();
Editable columns = fieldForColumns.getText();
Editable border = fieldForWidthOfBroder.getText();
TableAction tableAction = new TableAction(MainActivity.this.visualPane);
tableAction.insertTable(rows, columns, border);
}
});
Dialog dialog = null;
dialog = new Dialog(this);
switch (id) {
case IDD_CUSTOM_INSERT_TABLE:
dialog.setTitle("Insert table");
dialog.setContentView(R.layout.dialogtable);
return dialog;
case IDD_CUSTOM_INSERT_IMAGE:
dialog.setTitle("Insert image");
return dialog;
default:
return alert.create();
}
}
The appearance of the application before calling showDialog():
http://s015.radikal.ru/i330/1101/d0/f7cc38852dc6.jpg
The appearance of the application after calling showDialog():
http://s003.radikal.ru/i201/1101/f0/d1ebc436427f.jpg
Why it looks so terrible? What is wrong?
In your case you should use RelativeLayout instead of LinearLayout. So that you can set android:layout_weight and other relative properties on the TextViews to make their width equal.
Have a look at http://developer.android.com/resources/tutorials/views/hello-relativelayout.html and http://developer.android.com/reference/android/widget/RelativeLayout.html