Spinner with hint above selected element's string - java

I want to realize a Spinner with a "TextView with a hint", I already tried to pass another view beside R.layout.simple_spinner_item to the ArrayAdapter, but it doesn't work.
I want to do this by editing the Spinner element, not using a layout containing the TextView and the Spinner, how could i do it? I don't know how to realize a CustomAdapter, but, could that be the right way?
EDIT: Uploaded image of the Spinner Example (I hope it isn't broken)

Related

Android Element view

I have a button that creates an EditText, now I have a button that deletes the last element, but if I click it 2 times, I get an error because when I "spawn" an EditText I create a View:
code
vista = LayoutInflater.from(this).inflate(R.layout.edit, null);
When I go to delete it (so I delete 1 EditText) this view will be deleted too, but if I press the button once, I get error (don't remember which).
so i create an ArrayList that contains all the view spawned (every time i press the button for add them) and all do right, but when i have to remove EditText i remove Element by ArrayList but in app EditText will not be removed.
any suggestion?
I will give you the answer from what i have understood from your explanation. If I have not clear with what you needed. please do clarify so, that I can help you.
You are creating EditText dynamically and adding to the parent Layout.
parentView.addView(edittextObject);
Adding a edittext is working good. but, removing of edittext is not performing.
If this is your question.
Remove the selected edittext by clicking on delete button listener.
parentLayout.removeView((View) v.getParent());
This single line of code will remove edittext from parent layout.

Custom listview for image and text, or only text

I'm trying to build an app of my website(Just new to programming Java), getting data from my site is all going fine, but now i need to display it. I did some research online for the best way to do it(CustomListView), but coundnt find the solution yet, hope you guys can help me out.
The site i'm making an app of, is just a site where people can post text, or text with a photo.
Getting the text in my listview is going fine, but i also need images to display.
The problem is, how can i tell the Listview that it only contains text, so it wont display any image field, and how can i tell the ListView when there is a photo found by the post,that it also should display that one?
You can use a tag if the post contains an image or not for example if the data is in JSON form just set a tag
[{contains_image:"null"},{contains_image:"yes"}]
Then in your adapter check this tag if the result is a null set visibility gone
You have to create a layout containing a listView.
You have to create an xml lyout corresponding to one row of your list view.
You have to create an adapter which will populate data to insert in your listView
You have to create an onClickListener on your button to add data in your list
If you are using an ArrayAdapter or a CursorAdapter, add the new item you created to the list or the cursor used by your adapter and (notifyDataSetChanged() is automatically called), so your adapter will update the listview
Source : http://developer.android.com/resources/tutorials/views/hello-listview.html
Have at look at this article : http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/
Once you are go through with above set placeholder image which will be show for the items that do no get dynamic images from your server response.

Markable ListView with changing Actionbar Actions

Im trying to find out how I can mark things in ListViews with a longClick. After I selected one item ,the Actionbar should change with diffrent options (buttons like delete, add , copy etc) which Im able to execute.I really didnt know how I can find these examples because Its a kind unique I guess. I founded threads where I can Mark an Item which gets a diffrent color and nothing else. How can I achieve this ?
Before selecting :
After long click :
Well you can add an onLongClickListener in your ListView or RecyclerView but for each list_item you will have to specify a checkbox that will become visible only when you longClick the ListView.
Then if you do not want to mess up the actionBar with new menu items you can create a context menu that will do your job.
You can use a ListPopupWindow or you can also use a CardView with a contexual menu as shown in the picture here.

ScrollView contents update

I have a programmatically generated ScrollView with a TextView inside of it. I wish to update the text in the TextView from time to time and some have implemented a handler function to update the TextView GUI element. This seems to call/work correctly.
However, currently the only way I have found to actually get the TextView to show the appended information is to call:
consoleText.append("New text to add to TextView");
// then:
myScrollView.removeView(myTextView);
myScrollView.addView(myTextView);
This is not particularity optimal and was wondering how else I can refresh the contents of the ScrollView to show my newly added information...
Also:
invalidate();
postvalidate();
Do not seem to do anything - the TextView object has the new text in it (looking in debug) it's just not drawing it to the screen unless I call the add/remove function.
Thanks for any information/help you can give
FR
You should call invalidate() and requestLayout() on the TextView, and perhaps the ScrollView.

Android ListView - onListItemClick does not work properly

I created a ListView in Android, and a corresponding ListActivity. Each individual item in the ListView has just one TextView (I plan to add an image and a CheckBox later).The ListActivity overrides the onListItemClick to perform certain tasks on click of any item on the list.
Heres whats happening -
When I first tried clicking on any item, nothing happened.
I then tried setting the properties "Focusable" and "Focusable in Touch Mode" to false for the TextView, as mentioned here, here and here. The List items started recognizing clicks, but only when I clicked somewhere away from the TextView. Whenever I tried clicking on the TextView or anywhere near it, it did not work.
I also tried changing various attributes like Clickable, but nothing has worked so far.
Any idea what I could be doing wrong ?
Thanks
After playing around with virtually every attribute in my TextView, I finally found the reason why it was not working. It was because of the attribute android:inputType="text" in my TextView. I'm not sure why I added that piece of code (I probably copied the TextView from one of my other applications), but removing it solves my problem.
Class which will listen clicks on ListView should implement interface AdapterView.OnItemClickListener

Categories