Add views dynamically and get value from those views - android

I need help regarding adding new set of views and get value from those views.
In my example, I want to add 4 TextViews on Button click and open TimePicker from each view click and display new selected time on respective TextView.
Below is screenshot of view.

If these 4 views are fixed you could just create the xml and add them all to a single holder that you set invisible. If you mean by dynamic that it could be either 4 or 99 views, I'd recommend a RecyclerView. Plenty of examples on the internet. If you create a recyclerview with a custom adapter it is very easy to get the respective data per view.
For the future, please add more context to your question like what you've tried, what the result was and why this isn't your expected result. This is a very broad question.

Assuming that on clicking the clock button under the time section (on the right) you would want to set the selected time into the text field. You can simply call view.getParent() on click of the button and from the parent you can get the first child i.e child at 0 and set the text into the text field. This will work provided the button and textfield are within the same layout.

Related

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().

how to add editText in a custom list adapter

I want to add a row of 3 editTexts whenever the user removes focus from the last editText of the above row. I have tried various methods like inflating an individual linearLayout every time the user removes focus from the last editText. The problem in this method is I get a large number of linearLayouts to deal with which is not so efficient. Somebody suggested me to us custom list view but I don't know anything about it. Please help
Thanx in advance
You should create a custom list view. Look here.
In listview_item_row.xml, instead of using ImageView and TextView, you have to create a LinearLayout with 3 EditText. And finally, you have to create your own adapter like WeatherAdapter.java and inflate your 3 EditText.

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

Extended list view: Show text input inside once clicked

I am working on a UI where I have a list view. Each row has 2 information. One is Product name and the other is product ID stacked one over other. So each row has 2 lines of data.
What i want to do with this:
Once a user clicks on each row, it will further expand and show one input and one spinner. So it is basically for putting in Quantity and unit of measure.
Please let me know if this is achievable and if I can refer to some example.
What I need is more like
Taskos To Do List | Task List
https://play.google.com/store/apps/details?id=com.taskos&hl=en
All i need is that the category will not be expandable. Only the items will be expandable. All i need is an example of such app and then I can take it forward.
I think it could be done... you would need to put the extra widgets in your row layout, populate them and hide them upon list creation, then in your onListItemCLick you could unhide them.
Note I have no idea if this would work, but it seems reasonable that it might and it's what I would try and do to achieve the goal.
listView cannot be expanded. however you can use an expandablelistView
But the kind of functionality you want cannot be done this way(I guess.).
You can use
registerForContextMenu("your list View");
to register your list view
onCreateContextMenu
for the kind of action you want to be performed in your case its dialog with EditText and Spinner to have input from user

android listview

I have created one list view.. it is having 5 items...
Now I want split the list items...
when user clickon the first listitem or focus on first item then immediately it has to show followed some text views or other things..but it has to show same list..
and agian same when he clickon or focus on the second item that first item has to be close and second item has to act some thing....
I think you need to implement the concept of "Expandable Listview", so that the clicking on one item, it will be expanded with their sub-items.
Refer the android-sdk page of Expandable ListView: http://developer.android.com/reference/android/widget/ExpandableListView.html
For having an example, check this site: http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html
Pls, check the below image, do you want to perform as same ????
If you want to do the same, it is already given in the "API-Demos" at Views/Expandable Lists/1. Custom Adapter.
Enjoy !!
The problem is that you cannot use the standard ListView in your case, because in the standard ListView, the View of each row has to be one TextView.
In your case, you need it to be at least two TextViews (The standard Text, and the one that's gonna show up onClick/onFocus).
You have to create your custom ListAdapter, and override the getView() function.
Here is a code snippet that shows how to do it properly:
Custom Adapter
In the getView(), you have to inflate the XML file that describes your List Row, and return it.
In your case, I believe your XML file should contain 2 TextViews, one visible and one invisible.
Then, to handle the clicks, you can set a onItemClickListener on your ListView in your Activity class.
The best way may be to have your Activity class implementing onItemClickListener, and to use this onItemClickListener to handle those.
In the onClick() function, you just have to set the Visibility of your hidden TextView to VISIBLE.
You need to build custom rows, and handle showing more text on each row, there is no easy magicall way of doing it, but inflating your own rows, and setting a couple of attributes visibility isnt all that hard either.

Categories

Resources