I am trying to create a dialog box with Textview
in android like:
For creating the Textview
, I am using following function object.settype(textviewobject)
but there is no success.
I am trying to create a dialog box with Textview
in android like:
For creating the Textview
, I am using following function object.settype(textviewobject)
but there is no success.
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
TextView text1 =
(TextView)dialog.findViewById(R.id.text1);
Button proceed =
(Button)dialog.findViewById(R.id.button);
proceed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
dialog.xml
<?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="match_parent">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text1"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Proceed"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
I hope this helps
Use this:-
private void fn_showAlertDialog() {
new AlertDialog.Builder(YourActivity.this)
.setTitle("Title of your dialog")
.setMessage("Text that you want to show.")
.setCancelable(false)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//do your task
dialog.cancel();
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//do your task
dialog.cancel();
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
Use alertdialog like this, and create another layout for dialog:
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@SuppressLint("InflateParams") final View alertlayout = inflater.inflate(R.layout.notif_msg_dialog, null);
TextView text_main=(TextView)alertlayout.findViewById(R.id.notif_msg);
text_main.setText("YOUR TEXT");
builder.setView(alertlayout);
packsizeDialog=builder.create();
packsizeDialog.show();
Here, notif_msg_dialog.xml is layout which has textview
Just use AlertDialog.Builder and put your text in setMessage it will display
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage("your text");
builder.create();
builder.show();
You can get help from following post http://stackoverflow.com/questions/10903754/input-text-dialog-android