Android Element view - java

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.

Related

Content of Textview is deleten when i execute the intent(Android Studio)

For example i have an app to make a shopping list.First activity shows the content of the list.Second one is to add items to the list and it has textviews and button.I used textviews to add items to the list.If you click any textview, related item is added to the shopping list.But you need to click the button to go without adding anything.And i am using an intent for this but if i click that button everything i added the list earlier is deleted.What is the problem and solution(s)?ty
Pls add code ..
however I think the problem can be solved if you need to pass all the data to the 2nd activity and rcv the intent...and when you set the onclick listener for the button in 2nd activity...all data need to be passed back with the intent and set on the list.
If you add the code it will help

Spinner with hint above selected element's string

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)

Update TextView numerous times with Buttons

I am making a simple shopping cart application where the user can select items (via buttons) and their running total will be displayed in a text view.
I am fine with having the text view being updated on a single click but I am struggling to figure out how to write my code if the same button is pressed more than once. For example a button writes a value of £3 into the TextView, if this button was clicked again I want the TextView to increase to £6 and so on.
Further to this I want to be able to have more than value added to the TextView from different buttons. I imagine this is more of a Java question as opposed to Android but seeing as I'm a bit of a newbie to both all advice is welcome!
Into your class if you have price value add an incerementPriceValue and make get/set functions for the last one.
If user press the button
setIncrementValue(getIncrementValue()+priceValue);
setText(getIncrementValue+simbolstring);
Create a int variable count and on the click increase the count value and set that value on the textView

Copy paste option not appearing for EditText

I have created a Activity which extends FixedExpandableListActivity.
In my Activity, I am having EditText where in after entering some text, and doing a long press on the EditText, copy paste option is not appearing.
Doing multiple taps on the EditText, copy paste option pops up and disappear.
Issue is observed on 4.1.2.
Can some one please help out how to fix this issue.
My gremlin for this problem was a combination of windowSoftInputMode="adjustResize" and a View.OnLayoutChangeListener which was reparenting the EditText, for unrelated reasons. (Removing the EditText caused the copy/paste actions to disappear, sensibly enough.) Hard to track down.

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