Loading an image from assets and displaying in a dialog - java

I have a lot of images in the assets folder of my application that I'd like to display in a dialog popup. How can I go about doing this? I saw a similar question covering how to display the icons, with a pretty solid answer. But in the answer, the icons are pulled from a drawable. So, I suppose I have two options:
I have taken a look at the "Icons in a list dialog" thread but the answer posted uses drawables. I don't have a drawable for every single image because I have over 250 images.
Then I saw the "load drawable from assets" thread, but that doesn't quite get me there either. The "icons in a list dialog" expects a specific r.drawable.drawablename.
This is currently how I display the countries text:
public void onClick(Card card, View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(FtC_Setup.this);
builder.setTitle("Standard countries");
final CharSequence[] items = FtC_Play.allCountries.toArray(new CharSequence[FtC_Play.allCountries.size()]);
builder.setItems(items, null).show();
}

Related

Can I make clickable text in dynamic text files on android studio java?

I am trying to make a application that will allow people to tag more people. I want to make such that when a person clicks / taps in the name of another person in the TextView, it should go to the person's profile in the application (but not in the web). How can I make it?
Any insight of how to do would be respected!
A short code of how to do would be much respected!
TextView Content Example: I am here in the city with Manoj and he is enjoying this place.
I want to make this such that when a person clicks Manoj it should be gone to the next fragment or next activity. And the data should is to sent to the server, so it is something We cant just use only onClick Listener for the text, as the text is determined and the link is created by public user not me?
The image would help you understand!
First in your java file find your TextView by xml id
TextView tv = (TextView)findViewById(R.Id.textView);
then, you have to set click listner on the textView
tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// here you can use intent to naviaget to another activity
}
});

How to display an image in Dialog using Glide?

in my app there is an dialog with an image on it.
How can I display an image using glide?
Here is what I tried in my Fragment:
RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(R.drawable.goldversiondialog)
.error(R.drawable.goldversiondialog);
Glide.with(getActivity()).load(myURL).apply(options).into(goldimageview);
It is not working, it only displays the error image.
I also don't know what to write as context, "this" is not working in fragments.
How can I solve this?

Dismiss Popup Window on Touch Outside

I'm trying to open up a pop-up window with 4 buttons on it that will dismiss when a button is pressed or when the user clicks outside of the pop-up window. I would just make an alert dialogue, but that will only support 3 buttons.
There have been a lot of questions about this same thing, and I can't find any consistent answer or any answer that works for me (including the deprecated Bitmap Drawable). I've put all of the suggestions I've seen into my code, but to no avail.
Here's everything I've used so far:
//to create new popup window
LayoutInflater chooseMealInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View chooseMealLayout = chooseMealInflater.inflate(R.layout.choose_meal_dialog, null);
PopupWindow chooseMealPopup = new PopupWindow(chooseMealLayout, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
//to make popup dismiss on touch outside
chooseMealPopup.setOutsideTouchable(true);
chooseMealPopup.setFocusable(true);
chooseMealPopup.setContentView(chooseMealLayout);
chooseMealPopup.showAtLocation (chooseMealLayout, Gravity.CENTER,0,0);
chooseMealPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
I've tried to find everything I can, like keeping setFocusable before showAtLocation, but when I run the app, nothing happens when I click. Figured it might be something individual to my code, since I'm new and don't really know what I'm doing.
don't know what you really want to do...
if you want show dialog when click button
YourBtn.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
//what you want to do like show dialog
}
});

Android tab bar with different fragments and different action bar icons

Problem Description and Question
I'm using tab activity with action bar. In the HOME tab I have GridView which contains some items, like it is shown in the image below (Hot Lines, Taxi, Restaurants etc)
Wen user click on the items in the grid view I want my application to take following actions:
Change icon of application to grid view item image on which I pressed.
Change the test near the icon
Add standard back button near icon, which will go back to grid view screen.
Change the tab fragment to the one which I specify.
Like it is shown in the image below:
As I never deal with this kind of problems can you please give me example or share some link with me of how I can do this? and can I do this at all?
This might help:
Android studio - is possible to add tabs pointing to fragments from designer?
It is not exactly what you want, but a good start. If you are willing to put a bit of work in it, you should be able to get what you want. If you have a basic Frame to work with and more specific problems with this matter I will gladly help you out ^^
John
The first link you can check is THIS.
And you should read more about ActionBar.
The last thing is it's better if you google it first and try to write a code and when you got stuck somewhere share your code with us and ask for help.
You have to use actionbarsherlock library for it.
use android.support.v4.app.FragmentTabHost and TabWidget in the xml as shown below :
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
style="#style/yourstyle"/>
<FrameLayout
android:id="#+id/realtabcontent"
style="#style/realtabFrameContentStyle" />
<TabWidget
android:id="#android:id/tabs"
style="#style/yourtabstyle" />
</android.support.v4.app.FragmentTabHost>
Use SherlockFragmentActivity for showing the tabs.
In the activities code use following code (preferably in a function) to set the ctionbar icon and text :
activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setCustomView(R.layout.your_action_barlayout);
((TextView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.action_bar_title))).setText("your title");
ImageView homeButton = ((ImageView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.your_icon)));
homeButton.setVisibility(View.VISIBLE);
homeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, YourHOmeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
activity.finish();
}
});
ActionBar mActionBar = activity.getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.show();
then call this function with your icon and your text in your fragments onResume() method.

gallery view on android in alertdialog

I have source code for a slider puzzle. it delivers a random image for the puzzle and you can change alot of settings like tiles and numbers and what not. Its really easy to add pictures you just have to have them start with image_ and put them in the drawable folder. Only thing is it does not have a layout.xml i guess everything is written through the activity.
I want to have all of the pictures in like a gallery view when a button is clicked in the menu. i have seen all the gallery codes need code in the layout which this source code does not have so essentially i would like
rather than this
public void showAbout()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.title_about);
builder.setMessage(R.string.content_about);
builder.setPositiveButton(R.string.label_ok, null);
builder.setIcon(R.drawable.ic_launcher);
AlertDialog dlg = builder.create();
dlg.show();
((TextView) dlg.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}
i just want it to show up as a photo gallery

Categories

Resources