PDA

View Full Version : نمایش پنجره دیالوگ



abdoullah.aberi
چهارشنبه 08 آذر 1391, 20:31 عصر
دوستان می خوام بدونم چجوری میشه یک پنجره دیالوگ در برنامه داشت دوستان لطفا راهنمایی کنین:ناراحت:

farhadfery
پنج شنبه 09 آذر 1391, 10:12 صبح
چندین نوع دیالوگ هست. این مثال را ببینید برای alert:
http://www.mkyong.com/android/android-alert-dialog-example/
برای کاستوم کردن:
http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application

Modernidea
پنج شنبه 09 آذر 1391, 11:11 صبح
سلام

اطلاعات کامل در مورد دیالوگ ها را میتوانید در این آدرس مطالعه کنید: http://developer.android.com/guide/topics/ui/dialogs.html

این هم یک مثال:

AlertDialogDemo Activity:

package m.p.s;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AlertDialogDemo extends Activity {
Button btnGo;
EditText txtMsg;
String msg;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
txtMsg = (EditText)findViewById(R.id.txtMsg);

btnGo = (Button) findViewById(R.id.btnGo);
btnGo.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
AlertDialog diaBox = makeAndShowDialogBox();

diaBox.show();

txtMsg.setText("I am here!");
}

});
}//onCreate


private AlertDialog makeAndShowDialogBox(){

AlertDialog myQuittingDialogBox =

new AlertDialog.Builder(this)
//set message, title, and icon
.setTitle("Terminator")
.setMessage("Are you sure that you want to quit?")
.setIcon(R.drawable.ic_launcher)

//set three option buttons
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "YES" goes here
msg = "YES " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})//setPositiveButton
/* .setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "NO" goes here
msg = "Cancel " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})*/


.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "NO" goes here
msg = "NO " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})//setNegativeButton

.create();

return myQuittingDialogBox;
}

}//AndSelectionWidgets


dialog.xml Layout:

<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<Button
android:text="GO"
android:id="@+id/btnGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<EditText
android:hint="click the button"
android:id="@+id/txtMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>

</LinearLayout>

منبع: http://www.java-samples.com/showtutorial.php?tutorialid=1513

abdoullah.aberi
جمعه 10 آذر 1391, 08:26 صبح
مرسی از راهنمایی هایتون دوستان
:لبخندساده: