How to make a ListView act as an EditText - android

I am developing an application for Android, and for that I am trying to make a ListView act in such a way, that when a user presses an empty entry, he can start typing text directly into that empty entry, and that when the user touches any other part of the screen, it is saved. Is there a way to do this? I was thinking of using onClick somehow, but I have no concrete approach.

Here is one basic, general approach:
For each row of the ListView, create a layout that has a visible TextView and a EditText with the visibility set to gone.
Use an onClickListener for each row to swap the visibilities of the TextView and EditText (respectively, gone and visible) when the row is selected.
Track the active row for clicks to another row or background.
When the active row changes, set the value of the EditText to the TextView and return them to their original visible states.

Other approach that could be taken is using the View.OnFocusChangeListener and the TextWatcher you can get more detail about them here http://developer.android.com/reference/packages.html

Related

How to make a listView with textview and spinner and edittext

How can i create an android listview with row 1: textview + spinner row 2: textview + edittext etc.?
I have to make a form and i make it with xml layout but it's too long and bad for perfomance as the eclipse says.
Thank you!
ListView can be used if there is a repetition of same views in every row. This is where you get performance benefits given by adapters' recycling view mechanisms. With every row having different views they cannot be recycled and therefore no point in using the listview there.
So based on what kind of rows you have here are two solutions:
Solution 1:
Row 1 has textview + spinner, Row 2 has textview + EditText. And this combination repeats for the rest of the rows then you can try this. The xml where you create the layout of individual row for the ListView should be made a LinearLayout having two rows. ListView will create the rest of the rows for you by appending this LinearLayout.
Solution 2:
If each row is completely different from other (in terms of views used) then I would suggest using pagination. Divide your form questions into different relevant groups put each group on one page (scrollview). When user answers a set they have to navigate to the next page and so on.
As suggested by #Xaver Kapeller, I'd also suggest not using EditText in a ListView. It is very painful to debug keyboard issues and when the device orientation changes with keyboard open then as well. Instead of EditText ,use TextView which on tapping opens a Dialog box with a EditText. To keep the user interaction minimum.
You can focus the EditText as soon as the dialog open so that keyboard opens and user does not have to tap on the EditText. You can also dismiss the dialog by pressing the imeAction like Done on the soft keyboard or by pressing the hard back button. Dismissing the dialog should trigger a textview.setText("Data entered in the dialog box").

Manipulating a group view in a ExpandableListView from the child view

I'm building an ExpandableListView in which there are groups of radio buttons.
Currently, I am able to handle the click event on each radio button and select the corresponding one and deselect the others. But there is just one more thing needed to make it perfect. That is displaying the value of the selected checkbox in the group view so the user can see what is selected without expanding it.
For that purpose, I have a TextView in the group view. Is it possible to update that TextView when a checkbox is selected in the child view?
Here is a screenshot of what I have right now:
Basically what I want to accomplish is to make it write the value of the selected checkbox instead of "Regular".
Thanks.
in your example, it seems perfectly reasonable to save a reference to your TextView inside a member variable when it is created. you can then easily update its value by calling setText() on it from within your checkbox's click handler.
it is neither necessary nor desirable to call notifyDataSetChanged().

Which is better way to implement edit - listview with edittext or table layout with edittext

Need to implement edit in runtime. Which one is the best way to achieve it.
Edittext in Listview or dynamic table layout(inflating row xml) with edittext
Update:
My listview contains 7-8 view(Text view) in a list item. On click edit button using view switcher changed textviews to edit text. To get the entered value in edittext listening onfocuschanged. It brings very slow performance. Any better way to achieve it?
Update:
If my listview have 100 list items. Each item having 7-8 edittext. Need to listen all the edittext focuschange. My app hangs. What should i do?
EditText within ListView can cause you great grief down the lane given that views are recycled in listview.
Say you have tapped on the second row in a listview where all item rows contain a edittext and you have set adjustResize in your AndroidManifest.xml; after the soft keyboard pops up, the focus goes into the first view that can accept the focus which in this case will be the first edittext (row) of your listview. Yes, you can tap again on the desired edittext to regain focus. But it is an annoyance nevertheless. If you set adjustPan, then I have seen the the problem does not exist as such; if I recollect correctly, you cannot scroll down all the way to the end of your list. Again, another annoyance.
I'd suggest, you go with a ScrollView if the number of items in the list are less. I have been trying to solve this for the last couple of days - I ended up doing this - I replaced the edittext's with textview's in the listview; tapping on the textview would bring up a dialog fragment that contains the edittext.
Have you looked into the concept of a ViewHolder to keep a reference to the items of the listview? That should solve your multiple focus listener problems.

Android GridView Focus Issueon children?

I have a GridView to which a custom adapter is set. getView() method of the custom adapter returns a LinearLayout with two TextView and an EditText arranged horizontally. I have made a custom numeric keyboard for entering text in the EditText. Keyboard contains NEXT and PREV buttons as well which are creating problems. I want NEXT button to automatically focus the next EditText in the next row and similarly PREV button. NEXT button onKeyPress seems like:
View v=getWindow().getCurrentFocus().focusSearch(View.FOCUS_FORWARD);
if(v!=null)
v.requestFocus();
The code seems right. The problem is, suppose currently only three rows are visible of gridView,if the focus is on the third EditText and NEXT is pressed,it then focuses on nothing. I dont know how to solve this issue. If anyone knows how to solve it.
Thanx in advance.
Can you maintain a collection of ids of all the editText's in the same order, while adding them for rendering.
In that case, for clickHandler or NEXT/PREV button, u can check following:
clickHandler of PREV: if present selection is first in list, then you might want to set focus on last element in list.
clickHandler of NEXT: if present selection is last in list, then you might want to set focus on first element in list.
Alternatively, if you do not want a list roll back functionality, you can just check the position of element in list, and handle the brink elements any way u want them to be.
Hope I understood your problem correctly.
HTH

Swap out ListView item views

I have a ListView that can be in one of two states - viewing and editing.
In viewing state, the ListView should use one view to render rows - one with non-editable fields.
In editing state, it should use another view - one with editable fields.
When the ListView switches between states, all its rows should use the appropriate view for that state.
If the user has scrolled down the list, he/she should not lose their position when the ListView transitons between viewing and editing.
One of the solutions I attempted involved 2 adapters. But that was no good because it made the ListView pop back up to the first row whenever either adapter got set on the ListView.
Thanks much.
I've done something like this before. I had a set of complex views in a GalleryAdapter, one of which was a ViewFlipper that contained an EditText (the editable bit) and a TextView (the static part). There was a button to the right of the ViewFlipper, and when the user pressed that button I called showNext()/showPrevious() as appropriate to switch between the editable and visible views.
To clarify, I had one adapter that extended BaseAdapter, and in my getView() method I assigned onClickListeners to the buttons that would modify the objects in the view I was about to return.

Categories

Resources