Popup listView scroll and with imgaes - java

i want to create a popup with scroll listView and the listView will contain images,
i tried implement it with this code:
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
AlertDialog.Builder builder = new AlertDialog.Builder(groupContext);
builder.setTitle("Group");
builder.setItems(arrayNames, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), arrayNames[item], Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton("OK ", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.out.println("OK CLICKED");
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
this code is working for me, however i cant add images and the listView is not scroll
thanks alot

You need to define a custom dialog with XML layout containing ListView.
Steps:
Define a XML layout with ListView
set XML layout inside dialog using below:
dialog = new Dialog(MyActivity.this);
dialog.setContentView(R.layout.my_listView_layout);
Check this Simple example: Android Custom Dialog Example

Related

How to open a document on an alert dialog using PDFView on the app without using Intents

I have a document in the Firebase storage. I want to open that document and display it using an alert dialog and a PDFView from the pdf-viewer:2.8.2 library. This doesen't work when the setPositiveButton is clicked. Any ideas on what I might be doing wrong? This is the code am writing.
holder.postDocument.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.AlertDialog);
builder.setTitle("Open the document?");
builder.setPositiveButton("Open", new DialogInterface.OnClickListener() {
#Override
public void onClick(final DialogInterface dialog, int which) {
final PDFView pdfView = new PDFView(mContext, null);
pdfView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
pdfView.fromAsset(post.getPostdocument());
pdfView.loadPages();
builder.setView(pdfView);
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.show();
}
});
You Can Find Easily Solution and paste in Alert dialog https://github.com/eduxcellence/PDFViewer/find/master

How do I make my AlertDialog appear as soon as EditText has focus?

I want my AlertDialog to pop up as soon as my EditText has focus. Right now, I have to click on my EditText twice.
The first time I click my EditText, the soft keypad appears (for typing directly in my Edittext). Then, the second time I click the EditText, the AlertDialog appears.
How can I have it so only one click on the EditText is needed for the AlertDialog to pop up?
Here's my code:
In my onCreate...
//when user clicks on "commentName" EditText we want a new AlertDialog to open
commentName.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(NewContact.this);
builder.setTitle("Ur Comment:");
//start the following xml file/ layout
View viewInflated = LayoutInflater.from(NewContact.this).inflate(R.layout.comment_text_pop_up, null, false);
builder.setView(viewInflated);
// Set up the buttons
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
});
I got it to work according to your description with an OnFocusChangeListener.
Just replace the entire snippet from your question with the following. And paste in the AlertDialog code below the comment.
// commentName is your EditText
commentName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
return; // Prevents alert from being shown when losing focus.
}
// Your AlertDialog code goes here
}
});
The if (!hasFocus) prevents the alert from being shown when the user clicks something else that makes the EditText lose focus.
This did it for me, OnTouchListener:
//when user clicks on "commentname" edittext we want a new textbox to open
commentname.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
AlertDialog.Builder builder = new AlertDialog.Builder(NewContact.this);
builder.setTitle("Ur Comment:");
//start the following xml file/ layout
View viewInflated = LayoutInflater.from(NewContact.this).inflate(R.layout.comment_text_pop_up, null, false);
builder.setView(viewInflated);
// Set up the buttons
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
return true;
}
return false;
}
});
Another way you could do this with least code is by simply disabling focus on the EditText. You can do that by adding below attribute to your EditText...
<EditText
...
android:clickable="true"
android:focusable="false"/>
Then set OnClickListener on your EditText, and show the dialog in onClick() method.

Open two dialog together

I have two dialog.i open dialog one and click one button in adapter listview in dialog, and i want open another dialog to ask question for are you sure delet this item or no.
But just i can open one of them at a time.
What can i do?
viewHolder.btnDelet.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new DialogDelet(context).setOnListener(new ListenerDelet() {
#Override
public void onSuccess() {
listenerAdapterUserAndRole.unSelect(item);
}
#Override
public void onCancel() {
}
}).Show();
}
});
You can cancel first dialog when user is confirm or you want to open next dialog
like:
public void open(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Are you sure,
You wanted to make decision");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(MainActivity.this,"You clicked yes
button",Toast.LENGTH_LONG).show();
//cancel first dialog here
firstDialogObj.cancel;
// do your stuff contnious what you want
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}

Hyperlinking the Phone number in AlertDialog of Android

I have an AlertDialog having the text "For more information, Please Call 1-800-200-1000".
Here is my Code for the Alert Dialog Display while clicking on the ListView Item :
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final SpannableString s = new SpannableString("1-800-200-1000");
Linkify.addLinks(s, Linkify.ALL);
ListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
builder.setMessage("For more information, Please Call "+s)
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}});
Here i wish to hyperlink the "1-800-200-1000" and while clicking on this, another dialog for call function should be implemented.
Here is my AlertDialog for Call Function:
final Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to Call?");
builder.setCancelable(false);
builder.setPositiveButton("Call", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");dial.setData(Uri.parse("tel:"+ Phone));
startActivity(dial);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Toast.makeText(getApplicationContext(),"Activity will continue",Toast.LENGTH_LONG).show();
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
Please help me in two problems:
1.How to hyperlink the Phone number in the First Dialog?
2.how to embed the Call AlertDialog while clicking the Hyperlinked Phone Number?
Thanks in advance.
try this one:
Spannable spans = (Spannable) text;
ClickableSpan clickSpan = new ClickableSpan() {
#Override
public void onClick(View widget) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"+ url));
}
public void updateDrawState(TextPaint ds) {
//override link-centric text appearance
}
};
int index = (text.toString()).indexOf(url);
spans.setSpan(clickSpan, index, url.length() + index,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

How to Set icon(image) in DialogBox While Click in Button Event

I created a Button,While i Click that Button a new Dialog Box is Displayed.In that dialog Box i have set icon and text.text is Displayed but icon(image) is not displayed in dialog Box.
Here my Coding
Button btnteam_westernbulldogs=new Button(this);
btnteam_westernbulldogs.setId(team_westernbulldogsid);
btnteam_westernbulldogs.setBackgroundResource(R.drawable.team_westernbulldogs);
public void onClick(View v){
createbtnteam_westernbulldogs();
}
});
public void createbtnteam_westernbulldogs()
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setIcon(R.drawable.team_westernbulldogs);
alertDialog.setMessage("What kind of Banner do you Want to Create?");
alertDialog.setButton("Text", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
createText();
}
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
} });
Try this..
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setIcon(R.drawable.icon)
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
public void createbtnteam_westernbulldogs()
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setIcon(R.drawable.team_westernbulldogs);
alertDialog.setTitle("What kind of Banner do you Want to Create?");
alertDialog.setButton("Text", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
createText();
}
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
} });
You must call setTitle with non-empty string!
Icon is displayed only if there's also title.

Categories

Resources