Getting Button in Android Search Dialog - java

how can I access the button on the left in androids search dialog?
http://developer.android.com/images/search/search-ui.png
In the picture above I want to set an onClickListener onto the books icon.
Thanks in advance

Unfortunately, there's no way to do it. You could get to the layout and its elements if you had necessary ids. But the ids of the elements used by SearchDialog are not public, that's why you don't have access to them.

Related

Set The Visibility of The Whole Box

So in my app I have a registration form used to register other users. In my app I have 3 ranks (Admin, Patient, HCP). In the 'New HCP' form I want to hide something that is in my .xml file for the TextView. I am well aware of setVisibilty(View.GONE); but this doesn't work for my options because I have the boxes in a Constraint Layout.
My Question is:
How do I hide the whole box including its contents?
I tried this (but it only hid the contents and left the drawable box behind:
TextView consent_TextView = (TextView) findViewById(R.id.Register_text_Activity_consent);
consent_TextView.setVisibility(View.GONE);
TextView remind_TextView = (TextView) findViewById(R.id.Register_text_Activity_remind);
remind_TextView.setVisibility(View.GONE);
Please remember that I want to change this in Java not XML because if I do it in XML I will hide the box for everyone. Thanks!
As said in the comments, you can get a reference to the box you want to set the visibility either through View#getParent() or you can set its id programatically via View#setId(), bind it and set its visibility.

java android view structure

Just a simple maybe stupid question.
Is it ok to use multiple activities at once in an android application using an Inflater? I want to have multiple views on my screen without losing the previous view. For example, a user clicks on a button and a information screen shows up. Start Intent would convert the whole screen to the information screen activity.
Using an Inflater works but I'm just wondering if its the right way to display multiple views. Thanks in advance.
You should be using Fragments for this. Each fragment has a view/layout and you can move them in & out of your main view as you require. There are many tutorials
You can set the visibility of the views, e.g.:
Button b = (Button)findViewById(R.id.button);
b.setVisibility(View.GONE);

How can I programatically hide or suppress the search suggestions list?

How can I programatically hide the list of suggestions that pops up up below the SearchView?
There are times when I'd like the SearchView to not be inconified and to not have focus. I can do this both using the setIconified(false) and the clearFocus() methods respectively, but if the SearchView has any text in it, it will display the list of a search suggestions and I need to hide/suppress that.
searchView.setSuggestionsAdapter(null); did that trick for me.
Try to set an OnQueryTextListener to your search view, and return true on onQueryTextChange when you don't want any suggestions to show up.
If you've set a SearchView.OnQueryTextListener on your SearchView, you can return false in onQueryTextSubmit.
This will make sure suggestions get closed/hidden whenever the user submits the search query (by clicking on a suggestion or the "search" button on the keyboard).

Java ListView class?

What is the difference between a listview layout xml and a Listview Java class? I am trying to make it when a user inputs text and presses enter it comes on a set position on the right but when the user receives a reply it would show up on the left side of the list view. Like text messaging on android phones. Does anyone know how i can do this? With a java class or an xml layout? I want animations and dynamic content on the listview as well. Any ideas?
ListActivity provides you all the built-in features of and methods of ListView but only ListView can be added into the whole Activity. By using ListView in xml, you add multiple Views such as Buttons, EditText on the same Activity.
Basically, the xml is for seperating the design (the visuals) from the code (functionality).
Although you can do some funcationality via xml, it's usually better to do it in Java code in your class.
I guess you can create a ListView that will iterate through 2 different list enteries:
The first will show the data (the text in your case) on left and the second entry will show on the right. For each list entery you will create a different xml layout with widgets aligned to the left and right as needed.

View different images depending on what item in my list view I click

I'm fairly new to Android programming and I've got this project I need to finish and I'm currently stuck.
I've got a standard listview in a Menu class with an array containing around 20 different elements. So what I want to do is load images in an imageview depending on which item in the listview I click, and since I'm a beginner the only idea I had was to make a new activity for each imageview which seems like a pretty bad way to do it since I'd need about 20-30 new activities..
To sum things up what I want is:
Code for making ONE activity that will display a different image depending on which item in the listview I click, probably pretty basic coding I want as simple solution as possible.
If possible I'm also looking for a solution that includes an SQLite database that stores the URL of an image and then display it in a single activity, also depending on which item I press in my current listview.
(I hope you understand my needs, and if you need I can also post my current code for the Menu class if it helps you help me) Or you can just show me a different way to make this work, I appreciate every answer! Thanks in advance!
NOTE
And please keep in mind, I'm a noob at Java and Android so keep it rather simple or at least explain what you do.
When you click on a list item, display the image in another view in the same layout, unless you want the image to take up the entire screen real estate. If you want it in the entire screen, go to a new Activity by sending the activity an Intent.
Activities are the "controller" of your application. They interact with the visible UI and the input from the user. You don't need a separate activity for each image, just an activity that's associated with a "place" in the UI (an ImageView) where you'll display the image.
I'd start by adding the images as resources under res/drawable before going on to databases.
You are going to have to do most of this yourself. There really isn't any substitute for taking the time to learn Java and Android. There are several tutorials and Android University classes under the Resources tab in the Developers Guide; I suggest you do all of them.

Categories