How to remove empty white space in the custom dialog android? - android

How to remove the empty space in the dialog. My code-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_2x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_2x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_point_25_x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_point_25_x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.25X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_normal_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_75x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_75x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.75X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
</LinearLayout>
My Java Code
View alertLayout = View.inflate(this, R.layout.quality_dialog_layout, null);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setView(alertLayout);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();

Suggestion 1:
In order to customize the AlertDialog theme you have to create a new theme for it, which is a bit complicated and quite hard as you have also to create proper images etc.
Regarding this option you can check this topic here
Suggestion 2:
Include the button in the xml:
<Button android:text="OK"
style="?android:attr/borderlessButtonStyle" />
Suggestion 3:
Use the AlertDialog options and don't change the theme, this will add proper spacing in all options and follow the android theming so it will not look strange, but will not remove the spacing you mentioned:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setSingleChoiceItems(R.array.your_array_options, null/* no item preselected*/,
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// handle the item selection here
}
}
);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();
and the your_array_options will be in a file res/values/array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="your_array_options">
<item>2X</item>
<item>1.5X</item>
<item>1.25X</item>
...
</string-array>
</resources>
Suggestion 4:
In order to have full customized theme then do not use AlertDialog at all but DialogFragment:
public class MyDialogFragment extends DialogFragment {
// ...
// Empty constructor required for DialogFragment
public MyDialogFragment() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.quality_dialog_layout, container);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
// This will also require to add extra buttons in the xml!
// getDialog().setTitle("If you want to change the title");
return view;
}
}

Related

android alertdialog theme inconsistency error

I have an alert dialog which popups when you click a button in my app. The code is pretty simple and can be seen below:
final String[] options = {"Bar Graph", "Pie Chart", "Text Summary"};
AlertDialog.Builder builder = new AlertDialog.Builder(myActivity.this);
builder.setTitle("Choose a summary");
builder.setIcon(R.drawable.summaryicon);
builder.setItems(options, ... );
See below an image of what it looks like. This is good.
However, strangely sometimes when I build my app on the emulator the theme of the alert dialog changes and looks like this instead:
I cannot imagine what would be causing this random change in a seemingly unpredictable way.
I have tried using this line to set the theme manually, but it seems to have no effect.
ContextThemeWrapper themedContext = new ContextThemeWrapper( AnalysisActivity.this, android.R.style.ThemeOverlay_Material_Dialog_Alert );
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
...
I am confused and looking for a way to set the theme manually or ensure it doesn't change from the default.
I can't entirely tell if the rest of my app also experiences the same theme change because most has all been overridden by custom code, but I don't believe it is changing. Any ideas would be welcome.
Note: this alternate theme looks like an older theme so perhaps there is some version issue?
try this code...
step-1: create layout file of your alert dialog(this layout is your designed alertDialog)
step-2: and use this code
public void displayAlertDialog() {
LayoutInflater factory = LayoutInflater.from(this);
final View alertDialogView = factory.inflate(R.layout.alert_dialog, null);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setView(alertDialogView);
alertDialogView.findViewById(R.id.bar_graph).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your business logic
alertDialog.dismiss();
}
});
alertDialogView.findViewById(R.id.pie_chart).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your business logic
alertDialog.dismiss();
}
});
alertDialogView.findViewById(R.id.text_summary).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your business logic
alertDialog.dismiss();
}
});
alertDialog.show();
}
Along with Dinesh Sarma's answer the code I have now implemented to create the alertdialog activity can be seen here.
It creates a layout that looks like this:
Use this layout code in a file called alert_dialog.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
android:orientation="horizontal"
android:weightSum="12">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="7"
android:contentDescription="Icon"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scaleType="fitCenter"
app:srcCompat="#drawable/summaryicon" />
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5"
android:gravity="center_vertical"
android:text="Choose a Summary"
android:textSize="18sp"
android:textStyle="normal" />
</LinearLayout>
<Button
android:id="#+id/bar_graph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Pie Chart"
android:textAllCaps="false"
android:typeface="sans" />
<Button
android:id="#+id/pie_chart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Bar Graph"
android:textAllCaps="false"
android:typeface="sans" />
<Button
android:id="#+id/text_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Text Summary"
android:textAllCaps="false"
android:typeface="sans" />
</LinearLayout>

how to set the specific row item option(visible, invisible) in listview in android

frist my english skill weak.
description>
this is list view.
ㅡㅡㅡㅡㅡㅡㅡㅡ
ㅣㅡㅡㅡㅡㅡㅣㅢ <-- this is button , i init set invisible
ㅣㅡㅡㅡㅡㅡㅣㅢ
ㅣㅡㅡㅡㅡㅡㅣㅢ
ㅣㅡㅡㅡㅡㅡㅣㅢ
ㅣㅡㅡㅡㅡㅡ ////// <-- i want make visible button
ㅣㅡㅡㅡㅡㅡ ////// <-- specific position
I make the custom ListView
ListView row contains texts, Button.
The Button is set invisible option in xml file.
then, I want set the visible specific row button.
I tried that and failed
after make ArrayList for ListView, marking matching position like this
for(i=0; i<arraylist.size(); i++){
int t41=Integer.parseInt(arraylist.get(i).getm());
if(month == t41){
confirm_replay[i]=true;
temp55=i;
}
}
I can set the textValue. through adapter.getItem(int position).
but i don't know, how to control specific button.
also try add button into adapter. failed..
also search question in google but my eng skill bad. failed
add my code.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingTop="10dp"
android:text="match day(weekend)"
android:textSize="28dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:background="#2d000000"
android:layout_width="match_parent"
android:layout_height="3dp">
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/m"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:paddingLeft="10dp"
android:id="#+id/d"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/yoil"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/time"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/vsTeam"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/league"
android:paddingLeft="10dp"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/공갈"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_youtube"
android:text="다시보기"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/m"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:paddingLeft="10dp"
android:id="#+id/d"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/yoil"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/time"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/vsTeam"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/league"
android:paddingLeft="10dp"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/공갈"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_youtube"
android:text="다시보기"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"/>
</LinearLayout>
</LinearLayout>
</b>
adapter
class MlistViewAdapter extends BaseAdapter {
// Declare Variables
Context mContext;
LayoutInflater inflater;
private List<MatchInfomation> matchinformationlist = null;
private ArrayList<MatchInfomation> arraylist;
public MlistViewAdapter(Context context,
List<MatchInfomation> matchinformationlist) {
mContext = context;
this.matchinformationlist = matchinformationlist;
inflater = LayoutInflater.from(mContext);
this.arraylist = new ArrayList<MatchInfomation>();
this.arraylist.addAll(matchinformationlist);
}
public class ViewHolder {
TextView m;
TextView d;
TextView yoil;
TextView vsTeam;
TextView time;
TextView league;
}
#Override
public int getCount() {
return matchinformationlist.size();
}
#Override
public MatchInfomation getItem(int position) {
return matchinformationlist.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.activity_match_list, null);
button_youtube.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
});
// Locate the TextViews in listview_item.xml
holder.m = (TextView) view.findViewById(R.id.m);
holder.d = (TextView) view.findViewById(R.id.d);
holder.yoil = (TextView) view.findViewById(R.id.yoil);
holder.vsTeam = (TextView) view.findViewById(R.id.vsTeam);
holder.time = (TextView) view.findViewById(R.id.time);
holder.league = (TextView) view.findViewById(R.id.league);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.m.setText(matchinformationlist.get(position).getm());
holder.d.setText(matchinformationlist.get(position).getd());
holder.yoil.setText(matchinformationlist.get(position).getyoil());
holder.vsTeam.setText(matchinformationlist.get(position).getvsTeam());
holder.time.setText(matchinformationlist.get(position).gettime());
holder.league.setText(matchinformationlist.get(position).getleague());
return view;
}
}
If you want to adjust a specific row, you can use the position parameter in your getView() method in adapter. For instance;
if(position==55){
holder.m.setVisibility(View.GONE);
}
I'm not sure i understand your question.
If i'm right you juste want your button to be invisble for specific row. To do so add the specific line at the end of your getView method
yourButton.setVisibility(View.INVISIBLE)
If you want to hide the entire row, the best way will probably be to change your adapter to diplay only row with content.
before setting the values to the view check the condition whatever you want like:-
if condition is true then set your view visible
else set your view invisible
if(true){
button.setVisibility(View.VISIBLE);
}else{
button.setVisibility(View.GONE);
}

My custom dialog has top and bottom padding. How to delete that?

I created a custom dialog but I got an unexpected result.
The final appearance of the dialog is:
As you can see, my custom dialog is shown with a kind of padding in both top and bottom of the dialog, and I don't code it to do this...
The code is the next:
#Override
protected Dialog onCreateDialog(int id){
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newAsig = inflater.inflate(R.layout.nuevaasignatura_act, null);
//Also, down here I tried to shape the dialog by setting a functional resource, but
//the stroke should be blue, not grey.
RelativeLayout re = (RelativeLayout)newAsig.findViewById(R.id.layoutCrearAsig1);
re.setBackgroundResource(R.drawable.borde);
Typeface tf = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf");
ImageView ico = (ImageView)newAsig.findViewById(R.id.ivicono);
ico.setBackgroundResource(R.drawable.colorprincipal);
LinearLayout ly = (LinearLayout)newAsig.findViewById(R.id.layoutCrearAsig2);
ly.setBackgroundColor(Color.rgb(214, 217, 224));
TextView txt = (TextView)newAsig.findViewById(R.id.textviewnuevaasig);
txt.setTypeface(tf);
TextView txt1 = (TextView)newAsig.findViewById(R.id.textViewCarpeta);
txt1.setTypeface(tf);
txt1.setBackgroundResource(R.drawable.colorprincipal);
Button btn = (Button)newAsig.findViewById(R.id.buttonCrearAsig);
btn.setTypeface(tf);
switch (id){
case 0:
return new AlertDialog.Builder(this)
.setView(newAsig).create();
}return null;
And the XML file...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layoutCrearAsig1">
<ImageView
android:id="#+id/ivicono"
android:layout_width="50dp"
android:layout_height="50dp"
android:paddingLeft="4dp"
android:background="#color/DarkGray"
android:contentDescription="Icono ClassMarks"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:src="#drawable/icono_cm" />
<TextView
android:id="#+id/textViewCarpeta"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_toRightOf="#id/ivicono"
android:background="#color/DarkGray"
android:clickable="true"
android:gravity="center"
android:text="Carpeta"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="#+id/layoutCrearAsig2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/ivicono"
android:orientation="vertical">
<TextView
android:id="#+id/textviewnuevaasig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text="Crear nueva asignatura"
android:textSize="20sp" />
<EditText
android:id="#+id/edittextAsig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp" >
</EditText>
<Button
android:id="#+id/buttonCrearAsig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="20sp"
android:text="Crear"/>
</LinearLayout>
</RelativeLayout>
I hope you can help me. Thanks!
The idea is AlertDialog always has 5dp top and bottom padding.
Try something like this:
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setView(newAsig, 0, 0, 0, 0);
Try this validation.
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
builder = new AlertDialog.Builder(getActivity());
builder.setInverseBackgroundForced(true);
} else {
builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
}
}

Dynamically add edit text to a layout

I am trying to add an edit text view dynamically to a layout from the java class. However from what I have implemented nothing changes on my action. This is what I have:
public final void onCreate(final Bundle i){
int value = 0;
isEdit = false;
try
{
super.onCreate(i);
this.setContentView(R.layout.contactedit);
ContactList.soundIndicator = 0;
etPhoneNumber = new ArrayList<EditText>();
this.etPhoneNumber.add((EditText) this.findViewById(R.id.etPhoneNumberInput));
this.addNumberBtn = (Button) this.findViewById(R.id.addNumberEditText);
addNumberBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//etPhoneNumber.add(new EditText(ContactEdit.this));
try{
LinearLayout layout = (LinearLayout) findViewById(R.id.contacteditll);
EditText temp = new EditText(ContactEdit.this);
temp.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
etPhoneNumber.add(temp);
layout.addView(temp);
}catch(Exception e){
Log.d(TAG, "Failed to create new edit text");
}
}
});
}
This is the 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="wrap_content"
android:baselineAligned="true"
android:orientation="vertical"
android:id="#+id/contacteditll"
android:background="#drawable/darkimg">
<TextView
android:id="#+id/titlePrint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/titlePrompt"
/>
<Spinner
android:id="#+id/spContactTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/titlePrompt"
/>
<TextView
android:text="#string/namePrint"
android:id="#+id/namePrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:layout_width="match_parent"
android:hint="#string/returnName"
android:id="#+id/etFirstNameInput"
android:layout_height="wrap_content"
android:layout_toRightOf= "#+id/namePrint">
</EditText>
<TextView
android:text="#string/secondPrint"
android:id="#+id/secondPrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:layout_width="match_parent"
android:hint="#string/returnName"
android:id="#+id/etSecondNameInput"
android:layout_height="wrap_content"
android:layout_toRightOf= "#+id/namePrint">
</EditText>
<TextView android:id="#+id/numberPrint"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/numberPrint">
</TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etPhoneNumberInput"
android:hint="#string/returnNumber">
</EditText>
<Button android:id="#+id/addNumberEditText"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:freezesText="true"
android:editable="false"
android:text="ADD"
/>
<include
android:id="#+id/customedittext"
layout="#layout/myedittext"/>
<TextView android:id="#+id/emailPrint"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/emailPrint">
</TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etEmailAddressInput"
android:hint="#string/returnEmail">
</EditText>
<Button
android:freezesText="true"
android:editable="false"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:id="#+id/btnSaveButton"
android:layout_width="wrap_content"
android:text="#string/save"
android:layout_below="#+id/emailInput"
/>
</LinearLayout>
Whenever I click on my button the action is heard but nothing is done. The layout of the page does not change even though the new edit text is in my list of edit texts and I am adding the new edit text to the layout.
Any help would be appreciated thanks.
It sure gets added but you are not seeing it cause there is no space left. Two things to test:
Place the LinearLayout inside a ScrollView.
Use the weight parameter.
Using the weight parameter:
EditText temp = new EditText(ContactEdit.this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT, 1);
temp.setLayoutParams(params);

Issue with custom alert dialog

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.

Categories

Resources