मैं एक एंड्रॉइड संवाद में एक छवि प्रदर्शित करने की कोशिश कर रहा हूं। अगर मैं गैलरी ऐप से एक छवि का चयन करता हूं तो इसे एक संवाद में प्रदर्शित किया जाना चाहिए। मैंने चयनित छवि को गैलरी ऐप से लाने की कोशिश की है और एक अलर्ट संवाद के लिए अपना रास्ता पारित किया है।
4 जवाब
AlertDialog.Builder ImageDialog = new AlertDialog.Builder(MainActivity.this);
ImageDialog.setTitle("Title");
ImageView showImage = new ImageView(MainActivity.this);
ImageDialog.setView(showImage);
ImageDialog.setNegativeButton("ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1)
{
}
});
ImageDialog.show();
अरे इस link.. को फॉलो करें
सबसे पहले आपको अपना कस्टम डायलॉग लेआउट अपने डायलॉग बॉक्स में सेट करना होगा, जैसा कि नीचे दिया गया है।
setcontentview(R.layout.custom)
और इमेज को setImageResources(your image id)
के साथ सेट करें
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
अलर्ट डायलॉग बॉक्स में इमेज सेट करने के लिए आपको इस तरह एक कस्टम डायलॉग बनाना होगा
डायलॉग.एक्सएमएल
<?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="match_parent"
android:orientation="vertical">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/my_image"/>
</LinearLayout>
फिर अपनी गतिविधि में अपना कस्टम डायलॉग बॉक्स इस तरह दिखाएं
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.dialog, null);
builder.setView(dialogView)
.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create().show();
मैं AlertDialog दिखाने के लिए इस सरल विधि का उपयोग करता हूं:
private void showAlertDialog(Context mContext, String mTitle, String mBody, int mImage){
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setCancelable(true);
builder.setIcon(mImage);
if(mTitle.length()>0)
builder.setTitle(mTitle);
if(mBody.length()>0)
builder.setTitle(mBody);
builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
कॉल विधि:
showAlertDialog(mContext, "OOPS!", getString(R.string.massage_nointernet), R.drawable.ic_no_internet);
संबंधित सवाल
नए सवाल
android
एंड्रॉइड Google का मोबाइल ऑपरेटिंग सिस्टम है, जिसका उपयोग प्रोग्रामिंग या डिजिटल डिवाइस (स्मार्टफोन, टैबलेट, ऑटोमोबाइल्स, टीवी, वियर, ग्लास, IoT) को विकसित करने के लिए किया जाता है। एंड्रॉइड से संबंधित विषयों के लिए, एंड्रॉइड-विशिष्ट टैग जैसे कि एंड्रॉइड-इरादे, एंड्रॉइड-गतिविधि, एंड्रॉइड-एडॉप्टर आदि का उपयोग करें। विकास या प्रोग्रामिंग के अलावा अन्य प्रश्नों के लिए, लेकिन एंड्रॉइड फ्रेमवर्क से संबंधित हैं, इस लिंक का उपयोग करें: https: // android.stackexchange.com।