Buttons of alert dialog are cut off - java

I have an alert dialog which is started when someone touches a specific button. The alert dialog contains a view that is defined by a layout xml file. This layout contains several controls like check boxes, edit text fields, ... These controls are all inside a scrool view so that you can scroll through the content, if the whole content doesn't fit on the screen.
The problem is now that when I start this alert dialog, the buttons at the bottom are cut off screen. Altough the scrool bar is working and I can scroll through the content of the alert dialog, the buttons of the alert dialog are sometimes not totally visible.
This means:
Sometimes, all is fine and I can see the buttons of the alert dialog, an sometimes for strange reason, the buttons are cut off. I think it's an issue of the view being to big for the alert dialog and pushing the buttons more down.
For example, the view contains an edit text control. If I enter my name ther, everything is fine. But if I add a new line to this edit text, the buttons start to be cut off a little bit.
What did I wrong? I thought the scroll view would handle the oversize of my view so that the alert dialog fits to the screen.
My app is in portrait mode always.
The code of the view:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/bitteeinstellungenwaehlen" />
<EditText
android:id="#+id/edtTeam1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/hteam1"
android:text="Christoph" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/edtTeam2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/hteam2"
android:text="Lea" />
<EditText
android:id="#+id/edtTeam3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/hteam3"
android:text="Ludwig" />
<EditText
android:id="#+id/edtTeam4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/hteam4"
android:text="Anja" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/weitereeinstellungen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/chkModerationMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/moderationsmodus" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/info" />
</LinearLayout>
<CheckBox
android:id="#+id/chkPassOver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="#string/weitergeben" />
<CheckBox
android:id="#+id/chkBlackScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/blankscreen" />
</LinearLayout>
</ScrollView>
And that's how I start the alert dialog:
final AlertDialog.Builder alert = new AlertDialog.Builder(QuizEditor.this);
alert.setTitle(getString(R.string.speichernUndVorschau) + "...");
alert.setMessage("");
LayoutInflater inflater = LayoutInflater.from(QuizEditor.this);
final View layFrage = inflater.inflate(R.layout.layoutquizsettings,null);
alert.setView(layFrage);
final CheckBox chkModeration = (CheckBox) layFrage.findViewById(R.id.chkModerationMode);
final CheckBox chkPassOver = (CheckBox) layFrage.findViewById(R.id.chkPassOver);
final CheckBox chkBlackScreen = (CheckBox) layFrage.findViewById(R.id.chkBlackScreen);
final EditText edtTeam1 = (EditText) layFrage.findViewById(R.id.edtTeam1);
final EditText edtTeam2 = (EditText) layFrage.findViewById(R.id.edtTeam2);
final EditText edtTeam3 = (EditText) layFrage.findViewById(R.id.edtTeam3);
final EditText edtTeam4 = (EditText) layFrage.findViewById(R.id.edtTeam4);
alert.setNeutralButton(getString(R.string.speichernUndVorschau), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.setNegativeButton(getString(R.string.abbrechen), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
final AlertDialog dialog2 = alert.create();
dialog2.setOnShowListener(new OnShowListener() {
#Override
public void onShow(DialogInterface dialog) {
// TODO Auto-generated method stub
Button btnStarten = (Button) dialog2.getButton(AlertDialog.BUTTON_NEUTRAL);
btnStarten.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
ArrayList<String> teams = new ArrayList<String>();
String team1 = edtTeam1.getText().toString().trim();
String team2 = edtTeam2.getText().toString().trim();
String team3 = edtTeam3.getText().toString().trim();
String team4 = edtTeam4.getText().toString().trim();
if(team1.length() > 0) teams.add(team1);
if(team2.length() > 0) teams.add(team2);
if(team3.length() > 0) teams.add(team3);
if(team4.length() > 0) teams.add(team4);
if(teams.size() == 0) {
Toast.makeText(QuizEditor.this, getString(R.string.keinteameingegeben), Toast.LENGTH_SHORT).show();
}
else
{
// Quiz starten
dialog2.dismiss();
Intent myIntent;
if(chkBlackScreen.isChecked()) {
myIntent = new Intent(QuizEditor.this, BlackScreen.class);
}
else // Direkt das Quiz starten
{
myIntent = new Intent(QuizEditor.this, Quiz.class);
}
myIntent.putStringArrayListExtra("teams", teams);
myIntent.putExtra("moderation", chkModeration.isChecked());
myIntent.putExtra("passover", chkPassOver.isChecked());
myIntent.putExtra("filename", filename);
QuizEditor.this.startActivity(myIntent);
}
}
});
}
});
dialog2.show();
// dialog2.getWindow().setLayout(LayoutParams.WRAP_CONTENT, 300);
I am sorry for the German words. In the image you can see the problem.
Unfortunately I was not allowed to upload the screenshots I made...

The question was already solved in the comments, but I will add an answer for completeness and to show that it worked for me, too.
For an AlertDialog with a custom view, don't use the .setMessage line. Removing the following line in my project caused the buttons to stop getting clipped.
.setMessage("This is my message")

Set EditText lines to 1. Also set outer LinearLayout's to fill_parent.

Just make all the EditText property android:singleLine="true" and then try to test.

Related

How do I get the edit text value in text view from an alert box in android java?

I want to get some integer value from the user he/she click on the an alert box will show and asks for enter the total budget. When he/she puts the total budget in the alert box field then it'll be show in text view in the same activity.
Do refer to topic regarding custom dialog box:
How to create a Custom Dialog box in android?
You can create a custom dialog box that have a custom layout
R.layout.budget_dialog:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff">
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="#+id/edit_budget"
android:hint="Enter budget"
android:layout_below="#+id/a"
android:layout_marginTop="20dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="20dp"
android:textSize="18sp"
android:textColor="#ff000000"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="OK"
android:id="#+id/btn_dialog"
android:gravity="center_vertical|center_horizontal"
android:layout_below="#+id/text_dialog"
android:layout_marginBottom="20dp"
android:background="#drawable/btn_flat_red_selector"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff" />
</RelativeLayout>
And then obtain the value by:
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.budget_dialog);
final EditText edtBudget = dialog.findViewById(R.id.edit_budget);
Button dialogButton = dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Get budget string value
String budget = edtBudget.getText().toString();
//Do something with your value
dialog.dismiss();
}
});
dialog.show();
}
Each dialog has a positive button, and that positive button has a callback where you can get the text from edit text, like Edittext.getText and display it for textview like TextView.setText.
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Alert");
alertDialog.setMessage("Alert message to be shown");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// your work here
textview.setText = Edittext.getText
dialog.dismiss();
}
});
alertDialog.show();

How to make single-choice item

I want to make an alert dialog that contains a single-choice list item which will help the user choose the theme of the app. I have read on developer's website(Developers Website) how to make the multiple-choice items but I don't quite get how to make the single-choice list item
Thanks in Advance.
//MY CODE
public class ThemeDialog extends DialogFragment {
ArrayList mSelectedItems = new ArrayList(); // Track the selected items
public static ThemeDialog newInstance(){
ThemeDialog f = new ThemeDialog();
return f;
}
//Single-choice Item code
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
dialog.setTitle("Please Select");
dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//Action when cancel is clicked
dialog.dismiss();
}
});
CharSequence[] cs = new CharSequence[]{"Item-1", "Item-2","Item-3"};
dialog.setSingleChoiceItems(cs, defaultSelectedPosition, new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//Action when any item is clicked
dialog.dismiss();
}
});
return dialog.create();
}
dialog.setSingleChoiceItems(cs, position, selectItemListener); will create the single choice dialog.
create xml layout file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorWhite"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorPrimary">
</View>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="please select a theme"
android:textColor="#color/colorRed"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/cancle_booking_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<RadioButton
android:id="#+id/theme1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:text="theme1" />
<RadioButton
android:id="#+id/theme2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:text="theme2" />
<RadioButton
android:id="#+id/theme3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:text="theme3" />
<RadioButton
android:id="#+id/theme4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:text="theme4" />
<RadioButton
android:id="#+id/theme5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:text="theme5" />
</RadioGroup>
</LinearLayout>
now create custom dialog
final Button btnCancelbooking;
final TextView tvHideCancelDialog;
final RadioButton theme1, theme2, theme3, theme4, theme6;
final Dialog cancelDialog = new Dialog(BookingConfirmClass.this, R.style.DialogSlideAnim);
//cancelDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); /*use when not set in style file*/
cancelDialog.setContentView(R.layout.custom_cancel_booking);
getWindow().setGravity(Gravity.BOTTOM);
cancelDialog.show();
theme1 = (RadioButton) cancelDialog.findViewById(R.id.theme1);
theme2 = (RadioButton) cancelDialog.findViewById(R.id.theme2);
theme3 = (RadioButton) cancelDialog.findViewById(R.id.theme3);
theme4 = (RadioButton) cancelDialog.findViewById(R.id.theme4);
theme6 = (RadioButton) cancelDialog.findViewById(R.id.theme5);
final RadioGroup radioGroup = (RadioGroup) cancelDialog.findViewById(R.id.cancle_booking_radio_group);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
View radioButton = radioGroup.findViewById(checkedId);
int index = radioGroup.indexOfChild(radioButton);
switch (index) {
case 0:
//do your action for theme 1
break;
case 1:
//do your action for theme 2
break;
case 2:
//do your action for theme 3
break;
case 3:
//do your action for theme 4
break;
case 4:
//do your action for theme 5
break;
}
}
});
Using a final variable obviously won't work (since it can only be assigned once, at declaration time). So-called "global" variables are usually a code smell (especially when they become part of an Activity class, which is usually where AlertDialogs are created). The cleaner solution is to cast the DialogInterface object to an AlertDialog and then call getListView().getCheckedItemPosition(). Like this:
new AlertDialog.Builder(this)
.setSingleChoiceItems(items, 0, null)
.setPositiveButton(R.string.ok_button_label, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
int selectedPosition = ((AlertDialog)dialog).getListView().getCheckedItemPosition();
// Do something useful withe the position of the selected radio button
}
})
.show();
To make it more customize look at this -How to design Single Selection Dialog?
You need to add Radio buttons inside the RadioGroup Tag in ur dialog xml file.
custom_dialog.xml
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/RGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue Theme"
android:id="#+id/bluetheme"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Black Theme"
android:id="#+id/blacktheme"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Brown Theme"
android:id="#+id/browntheme" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Orange Theme"
android:id="#+id/orangetheme"/>
</RadioGroup>
Just attach this xml with dialog fragment...this is just simple example..u can use it in ur way also
public class DFragment extends DialogFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.custom_dialog, container,
false);
getDialog().setTitle("DialogFragment Tutorial");
// Do something else
return rootView;
}
}

Pass data from dialog to activity Android

I have problem.
I made method which creates Dialog with my own layout. And I have no idea how to pass values (Strings) from my EdiText and asing to any variable in my Activity.
In comments you can see how I was trying to solve this.
Java method
public void makeDialog(){
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_ip);
dialog.setTitle("IP connection");
// Todo passing value from dialog to activity
// final EditText ipValueConnection = (EditText)findViewById(R.id.ipValueConnection);
// ipValueConnection.setOnClickListener(this);
// EditText portValueConnection = (EditText)findViewById(R.id.portValueConnection);
// Toast.makeText(context, ipValueConnection.getText().toString(), Toast.LENGTH_LONG).show();
Button dialogButtonLogin = (Button) dialog.findViewById(R.id.dialogButtonLogin);
// if button is clicked, close the custom dialog
dialogButtonLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tryToConnect();
dialog.dismiss();
}
});
// set the custom dialog components - text, image and button
// TextView text = (TextView) dialog.findViewById(R.id.IP);
dialog.show();
}
XML layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/antena"
android:layout_width="220dp"
android:layout_height="120dp"
android:scaleType="centerInside"
android:background="#FFFFBB33"
android:contentDescription="#string/app_name"
android:adjustViewBounds="true"
/>
<EditText
android:id="#+id/ipValueConnection"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:hint="IP" />
<EditText
android:id="#+id/portValueConnection"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif"
android:hint="PORT"/>
<Button
android:id="#+id/dialogButtonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="5dp"
/>
</LinearLayout>
Create a interface
public interface OnClickInterface {
public void onClick();
}
call it instantiate it in your activity onCreate()
OnClickInterface onClickInterface = new OnClickInterface() {
#Override
public void onClick() {
//Call Method from here
requiredMethod();
}
};
//And in your dialog classs or method
public void makeDialog(OnClickInterface onClickInterface){
//Your code
dialogButtonLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onClickInterface.onClick();
dialog.dismiss();
}
});
}
The error you are getting means that a reference to the editText cannot be found in the current layout file. You have find the EditText in the custom dialog view instead of the activity view.
So instead of:
final EditText ipValueConnection =(EditText)findViewById(R.id.ipValueConnection);
use:
final EditText ipValueConnection =(EditText)dialog.findViewById(R.id.ipValueConnection);
If i have understood your question correctly,
your edit text is in dialog_ip so you need to use
final EditText ipValueConnection = (EditText) dialog.findViewById(R.id.ipValueConnection);
Then you can get text from edit text as
String text= ipValueConnection.getText().toString;
And use that variable in your activity.

How can I create a popup menu to be shown when I click on an item in listview(android studio)?

I'm new to android developing...
I've created a listview using Strings and Array Adapter in setting.java:
public class setting extends Activity {
ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting_layout);
String[] settingOptions = new String[]{getString(R.string.settingInterface), getString(R.string.settingLanguages), getString(R.string.settingInfo)};
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, android.R.id.text1, settingOptions);
listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
}
and this is my setting_layout.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">
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
setting_layout Activity(listView)
I want to create a popup menu for Languages item that when I click on it,shows some other languages translations.
I've created a string.xml in other languages but I don't know how to use it in popup menu.
1:How can I make a popup menu shown when I click on Languages item?
2:How to put other languages in popup menu?
Thanks in advance
for pop up you can create a dialog using dialog builder, it can be a custom one(xml layout), or can be created dynamically (programmatically using java)
check out this code for a pop up view :)
for example I have this function that I call inside the onClick:
private void showFlavorDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
View promptView;
LayoutInflater layoutInflater = LayoutInflater.from(myActivity.this); //this gets the custom layout inflater
promptView = layoutInflater.inflate(R.layout.dialog_flavors_ar, null); // here you put the custom xml leyout name
final EditText editText = (EditText) promptView.findViewById(R.id.editText_note); //my layout has an edit text and button in it and I want to use it, so call the findviewbyid
Button add_note = (Button) promptView.findViewById(R.id.button_note);
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); //this removes full screen keyboard, so the keyboard doesnt take the whole screen.
add_note.setOnClickListener(new View.OnClickListener() { //onClick for the button
#Override
public void onClick(View v) {
otherNote_b = true;
flavor = editText.getText().toString();
new httpSetFlavor().execute();
alertDialogFL.cancel();
}
});
if (selectedflavorNameEn.size() > 1) {
flavorsGrid = (GridView) promptView.findViewById(R.id.gridView_flavors); // I also have a gridview in the layout
flavorsGridAdapter adapter = new flavorsGridAdapter(OrderActivityAr.this,
selectedflavorNameEn);
flavorsGrid.setAdapter(adapter); // this is a custom adapter for the grid which you wont need
}
alertDialogBuilder.setTitle(R.string.flavor_ar); //title of the popup window
alertDialogBuilder.setView(promptView); //set view of the popup to your custom view
alertDialogBuilder.setCancelable(true); //this makes the popup cancelable on back button pressed
alertDialogBuilder.setPositiveButton(R.string.delete_flavor_ar, new DialogInterface.OnClickListener() { //this is a button for the popup if you want one
public void onClick(DialogInterface dialog, int id) {
deleteFlavor = true;
new httpSetFlavor().execute();
}
});
alertDialogBuilder.setNegativeButton(R.string.back_ar, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialogFL = alertDialogBuilder.create(); //here you create the dialog using its builder
alertDialogFL.show(); // show it on screen
}
and this is my custom layout xml file, so you can just put any layout you want in it and use it later :)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<GridView
android:layout_width="wrap_content"
android:layout_height="150dp"
android:id="#+id/gridView_flavors"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:numColumns="3"
android:horizontalSpacing="2dp"
android:verticalSpacing="2dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/gridView_flavors"
android:layout_marginTop="5dp">
<Button
style="?android:attr/buttonStyleSmall"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_width="wrap_content"
android:singleLine="true"
android:layout_height="wrap_content"
android:text="#string/add_note_ar"
android:id="#+id/button_note"
android:layout_below="#+id/gridView_flavors"
android:textSize="20dp"
android:background="#drawable/button_plain_green"
android:textColor="#000"
android:layout_weight="0" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_note"
android:layout_below="#+id/gridView_flavors"
android:layout_toRightOf="#+id/other_text"
android:layout_marginTop="2dp"
android:layout_toLeftOf="#+id/button_note"
android:layout_toStartOf="#+id/button_note"
android:layout_weight="1"
android:gravity="right" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/other_note_ar"
android:id="#+id/other_text"
android:layout_below="#+id/gridView_flavors"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/editText_note"
android:gravity="center"
android:textSize="20dp"
android:layout_weight="0"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<com.andexert.library.RippleView
android:layout_width="wrap_content"
android:id="#+id/ripple_button"
android:layout_weight="0"
android:layout_height="wrap_content"></com.andexert.library.RippleView>
</TableRow>
</RelativeLayout>
this is the look of the layout:
and in your case you can use listview in the custom layout as well :) but with custom list item for example a radio button.
as for displaying other languages saved in xml
well you should have them saved in res/strings.xml
you can use the strings in an array of strings like this:
String strArray[]={
getResources().getString(R.string.string1),
getResources().getString(R.string.string2),
getResources().getString(R.string.string3),
getResources().getString(R.string.string4)
};

android popup windows

i want to create in my app a popup window with enter text field and ok and cancel buttons:
this is my code in MainActivity:
forgotPassword.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
View pview = inflater.inflate(R.layout.forgot_password_popup,(ViewGroup)findViewById(R.layout.login));
final PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.forgot_password_popup,(ViewGroup)findViewById(R.layout.login)));
pw.showAtLocation(v, Gravity.LEFT,0,0);
pw.update(8,-70,150,270);
//if onclick written here, it gives null pointer exception.
Button okbtn=(Button)pview.findViewById(R.id.okbtn);
Button cancelbtn = (Button)pview.findViewById(R.id.cancelbtn);
final EditText emailText = (EditText) pview.findViewById(R.id.EmailText);
okbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try {
ParseUser.requestPasswordReset(emailText.getText().toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
cancelbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
pw.dismiss();
}
});
}
});
and here is my forgot password_popup.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:orientation="vertical" >
<EditText
android:id="#+id/EmailText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:hint="Enter Email Address"
android:inputType="textEmailAddress"
android:password="true"
android:singleLine="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/okbtn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="OK" />
<Button
android:id="#+id/cancelbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
however it cut off (i cant see the text field or the cancel button, also, there is no any background to the popup windows (i want a transparent background)
and also, i cant click on the ok button, so something wrong with my code
i will be glad for help
this is how it looks like:
http://img827.imageshack.us/img827/9545/capturehdv.png
thanks alot
Simple solution is Take a tranparent image and set it as background for your popup layout.
And also try
android:background=#null

Categories

Resources