Custom alert dialog view does not show things set dynamically - java

I have made an alert dialog which shows a custom view,
Java Code
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.about_me_alert, null);
CircleImageView imageView = view.findViewById(R.id.image);
Glide.with(view).load("https://example.com/example.jpg").into(imageView);
TextView title = view.findViewById(R.id.title);
title.setText("This is a title");
TextView note = view.findViewById(R.id.note);
note.setText("This is a note");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(view);
builder.setPositiveButton("Okay", (dialog, which) -> dialog.dismiss()).show();
XML Layout- about_me_alert.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"
android:background="?attr/cardbackground"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/image"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_centerHorizontal="true"
android:layout_margin="8dp" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:textColor="#color/white"
android:textSize="16sp" />
<TextView
android:id="#+id/note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:textColor="#color/white"
android:textSize="16sp" />
</RelativeLayout>
When alert is shown, it reserves space for the imageview, and two textviews but does not set text or image.
NOTE: This only happens when I make a production apk for release, not while I am testing on my phone.

Related

How to creat Dialog PopUp window with custom Layout?

I'm trying to create a dialog popup window with a custom layout, but my custom layout height and popup window height is not matching. Also, the popup window is hiding a button. What should I do, how can I match my popup window height with a custom layout?
Please help me.
I want my popup window to look like this
But it is looking like this
My custom layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="336dp"
android:layout_height="156dp"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|center"
android:background="#drawable/rectangle"
android:layout_marginBottom="88dp">
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="58dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/bikepic" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="64dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/delivery" />
<TextView
android:id="#+id/biketextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="69dp"
android:layout_marginTop="17dp"
android:background="#drawable/biketextview"
android:gravity="center"
android:text="Bike"
android:textColor="#FFFFFF"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/deliverytextView"
android:layout_width="64dp"
android:layout_height="18dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="64dp"
android:background="#drawable/deliverytextview"
android:gravity="center"
android:text="Delivery"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView7"
android:layout_width="23dp"
android:layout_height="14dp"
android:layout_marginStart="78dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="74"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView5" />
<TextView
android:id="#+id/textView8"
android:layout_width="23dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="80dp"
android:gravity="center"
android:text="39"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView6" />
popup dialog code
popAddPost = new Dialog(this);
popAddPost.setContentView(R.layout.pop_up_confirm_pickup);
//popAddPost.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//popAddPost.getWindow().setLayout(Toolbar.LayoutParams.MATCH_PARENT,Toolbar.LayoutParams.WRAP_CONTENT);
popAddPost.getWindow().getAttributes().gravity = Gravity.BOTTOM;
In your xml, the parent layout is using RelativeLayout LayoutParams on a ConstraintLayout
Remove android:layout_alignParentLeft="true" and android:layout_alignParentEnd="true"
ConstraintLayout also doesn't support layout_gravity so you can also remove that.
<androidx.constraintlayout.widget.ConstraintLayout
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="#drawable/rectangle"
android:layout_marginBottom="88dp">
Code
popAddPost = new Dialog(this);
popAddPost.setContentView(R.layout.pop_up_confirm_pickup);
Objects.requireNonNull(popAddPost.getWindow()).setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popAddPost.show();
EDIT
To position the dialog at the bottom use this:
Window window = popAddPost.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.BOTTOM;
window.setAttributes(params);
This is how i do it:
private AlertDialog alertDialog;
alertDialog = buildDialog();
alertDialog.show();
private AlertDialog buildDialog(){
final AlertDialog dialogBuilder = new AlertDialog.Builder(context).create();
LayoutInflater inflater = LayoutInflater.from(context);
View dialogView = inflater.inflate(R.layout.dialog, null);
dialogBuilder.setView(dialogView);
dialogBuilder.setButton(DialogInterface.BUTTON_NEGATIVE, "CLOSE", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialogBuilder.dismiss();
}
});
return dialogBuilder;
}
I think dialog is not a good solution for your problem as a dialog would have its own window with overlay.
As I can see you want the dialog to be at the bottom of the screen, which makes the BottomSheet as a perfect match for your problem.
You can use the following to get started with:
https://www.androidhive.info/2017/12/android-working-with-bottom-sheet/
https://material.io/develop/android/components/bottom-sheet-behavior/
https://medium.com/#droidbyme/android-bottom-sheet-7e9cfcec6427
With BottomSheet, you would get a separate window just like dialog without the overlay you are facing.

in android display layout 1 to left and layout 2 to the right [duplicate]

This question already has answers here:
create a chatView layout in android
(4 answers)
Closed 4 years ago.
in android i am trying to change the layout base on who the message is from.
if the message is from me then display the layout mymessage.xml to the right else display message.xml to the left.
i used if condition, but i don't know how to display one layout to the right and the second to the left,
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO
View messageView = null;
// Get a reference to the LayoutInflater. This helps construct the
// view from the layout file
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Change the layout based on who the message is from
if (messages.get(position).fromMe()) {
messageView = inflater.inflate(R.layout.mymessage , parent, false);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.mytimeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.mymessageTextView);
msgView.setText(messages.get(position).getMessage());
} else {
messageView = inflater.inflate(R.layout.message , parent, true);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.timeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.messageTextView);
msgView.setText(messages.get(position).getMessage());
}
return messageView;
}
try this layout for mymessage.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">
<TextView
android:id="#+id/mytimeTextView"
android:alpha="0.5"
android:layout_alignParentRight="true"
android:text="5:00 pm"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_below="#+id/mytimeTextView"
android:id="#+id/mymessageTextView"
android:layout_alignParentRight="true"
android:text="mymessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
and similarly this for message.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">
<TextView
android:id="#+id/timeTextView"
android:alpha="0.5"
android:layout_alignParentLeft="true"
android:text="5:00 pm"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_below="#+id/timeTextView"
android:id="#+id/messageTextView"
android:layout_alignParentLeft="true"
android:text="yourmessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
for message.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">
<LinearLayout
android:id="#+id/receive_ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/message_box"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:visibility="visible">
<TextView
android:id="#+id/tv_receiver_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="User 1"
android:textColor="#color/NavDrawerTextColor"
android:textSize="14dp"/>
<TextView
android:id="#+id/tvmessagetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hi"
android:textColor="#color/MessageText"
android:textSize="14dp"/>
<TextView
android:id="#+id/timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:text="04:16 pm"
android:textSize="10dp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/send_ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"
android:background="#drawable/message_sender_box"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:visibility="visible">
<TextView
android:id="#+id/tvmessagetext_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="user 2"
android:textColor="#color/White"
android:textSize="14dp"/>
<TextView
android:id="#+id/timestamp_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:text="Hello"
android:textColor="#color/White"
android:textSize="10dp"/>
</LinearLayout>
</RelativeLayout>
for java class: getview()
convertView = inflater.inflate(R.layout.message,parent, false);
if (messages.get(position).fromMe()) {
// for reference receive_ll is GONE and send_ll layout is VISIBLE
} else {
// for reference receive_ll layout is VISIBLE and send_ll layout GONE
}
For left.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/msgr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginBottom="5dp"
android:layout_marginRight="20dp"
android:background="#drawable/textview"
android:paddingBottom="8dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:text="Sampleleft"
android:textColor="#000" />
</RelativeLayout>
For right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/msgr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:background="#drawable/textview"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:text="Sample"
android:textColor="#000" />
</LinearLayout>
just replace this
// Change the layout based on who the message is from
if (messages.get(position).fromMe()) {
messageView = inflater.inflate(R.layout.left , parent, false);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.mytimeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.mymessageTextView);
msgView.setText(messages.get(position).getMessage());
} else {
messageView = inflater.inflate(R.layout.right , parent, true);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.timeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.messageTextView);
msgView.setText(messages.get(position).getMessage());
}
Just make it simple .
create single layout contain two category
set the data's in the fields
And VISIBLE GONE the layout by the type
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/sender_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
//sender side
</LinearLayout>
<LinearLayout
android:id="#+id/reciver_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
//reciver side
</LinearLayout></LinearLayout>
if the message type is sender means visible thesender_layout else visible the reciver_layout
when you getting myMessage that time show mymessage layout other layout will hide like make below codition ...
if (messages.get(position).fromMe()) {
myMessageView = inflater.inflate(R.layout.mymessage , parent, false);
myMessageView.setVisibility(View.VISIBLE);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.mytimeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.mymessageTextView);
msgView.setText(messages.get(position).getMessage());
messageView.setVisibility(View.GONE);
} else {
messageView = inflater.inflate(R.layout.message , parent, true);
messageView.setVisibility(View.VISIBLE);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.timeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.messageTextView);
msgView.setText(messages.get(position).getMessage());
myMessageView.setVisibility(View.GONE);
}

Custom ActionBar setCustomView() has extra margins

I am not really good when it comes to designing. I already have an ActionBar I just want to customize it.
As you can see in the screenshot it is not properly aligned. The yellow one is the default ActionBar and the Gray is the customized one. What should I do?
Here is my xml code for the ActionBar:
<RelativeLayout 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="50dp"
android:background="#color/grey_700" >
<TextView
android:id="#+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
app:srcCompat="#drawable/pic" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:background="#null"
android:src="#android:drawable/ic_menu_rotate" />
And inside my onCreate()
ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.st_actionbar, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText("My Own Title");
ImageButton imageButton = (ImageButton) mCustomView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
This ActionBar is out of date, and if you don't have to use ActionBar I recommend you use toolbar.You can have a look at the official web site, https://developer.android.com/reference/android/support/v7/widget/Toolbar.html

Add Defined TextInputLayout Dynamically and Programatically

I am trying to add a TextInputLayout with an EditText based on a number that the user selects from a Spinner. I already have the TextInputLayout attributes defined in XML and was hoping to simple just add them programmatically based on the number that the user selects from the spinner:
XML:
<FrameLayout
android:background="#drawable/image_border"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".525">
<Button
android:id="#+id/add_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Click to Add Image" />
</FrameLayout>
<LinearLayout
android:orientation="vertical"
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".475">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/create_poll_question_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
android:hint="#string/create_poll_question" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/how_many_answers_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/how_many_answers_text"
android:textColor="#color/black"
android:textSize="16sp" />
<Spinner
android:id="#+id/number_of_answers_spinner"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:layout_height="24dp"
android:background="#android:drawable/btn_dropdown" />
</LinearLayout>
<!--Want to Add Programatically -->
<android.support.design.widget.TextInputLayout
android:id="#+id/create_poll_answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/create_poll_answer_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Here is the code I am currently using, but it does not add dynamically based on the view I already created:
public class YourItemSelectedListener implements AdapterView.OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String selected = parent.getItemAtPosition(pos).toString();
Toast.makeText(getActivity().getApplicationContext(), selected, Toast.LENGTH_SHORT).show();
for (int i = 0; i < Integer.parseInt(selected); i++) {
ViewGroup layout = (ViewGroup) mRootView.findViewById(R.id.create_poll_linearlayout);
EditText editText = new EditText(getActivity());
editText.setHint("Poll Answer");
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(layoutParams);
TextInputLayout newAnswer = new TextInputLayout(getActivity());
newAnswer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
newAnswer.addView(editText, layoutParams);
layout.addView(newAnswer);
}
}
Easiest way to do such dynamic injections of view is to use ButterKnife library by JakeWharton
http://jakewharton.github.io/butterknife/
You can use it like in your activity's declaration part:
#BindView(R.id.title) TextInputLayout textInputLayout;
Then bind it inside onCreate() like:
ButterKnife.bind(this);
This will roughly be equivalent to inflating and finding the view by id.
Moreover, the library helps to dynamically set drawables,etc. with ease as well
Add
android:id="#+id/create_poll_linearlayout"
to your root LinearLayout.

EditText.getText() returns the default/initial value when called in an inner class

I sought numerous answers/similar questions and non solved my problem. I have a custom dialog implemented in a class that extends "DialogFragment". When I try to get text from any of the layout components I get the initial default text that I sat.
Code snippet :
public class input1_frag extends DialogFragment
{
View v;
LayoutInflater inflater;
EditText email_field,passwd_field;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
inflater = getActivity().getLayoutInflater();
builder.setTitle("Identity verification");
// Inflate and set the layout for the dialog
builder.setView(inflater.inflate(R.layout.input_dialog, null));
builder.setPositiveButton("Modify account", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
v = inflater.inflate(R.layout.input_dialog, null);
email_field = (EditText) v.findViewById(R.id.input_dialog_email0);
passwd_field = (EditText) v.findViewById(R.id.input_dialog_passwd0);
String fetched_email = email_field.getText().toString();
String fetched_passwd = passwd_field.getText().toString();
});}}
input.dialog.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your old data"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow android:id="#+id/tableRow_space_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View android:layout_width="fill_parent"
android:layout_height="20dp">
</View>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/input_dialog_email0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:text="E-mail" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/input_dialog_passwd0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:text="xxx" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TableRow>
</TableLayout>
I made the view & the inflater global to avoid making them final. Yet it still returns the initial text from the textfield.
Remove following line from your onClick method and use it in builder.setView(). Because of this line view is being reset to its original form and changes made to edit text is lost.
v = inflater.inflate(R.layout.input_dialog, null);
Like this
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
inflater = getActivity().getLayoutInflater();
builder.setTitle("Identity verification");
// Inflate and set the layout for the dialog
v = inflater.inflate(R.layout.input_dialog, null);
builder.setView(v);
builder.setPositiveButton("Modify account", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
email_field =
...
...

Categories