Adding another line of components to relativelayout - java

Anyone know how to get this result?
Description:
When the '+' button is clicked, another line of EditText, Spinner, EditText and Button will be displayed below the line. And lines go on adding if the user click on the '+' button.
Thanks!

I think the best would be to implement a custom ViewGroup extending a LinearLayout in vertical orientation.
You'll register an OnClickListener on the last button: if the row is the last in the list, you'll inflate a new ingredients_item.xml and add it to your view (also you'll refresh the drawable from + to -), otherwise remove the current row.
Your custom view will provide a method like List<Ingredient> getIngredients(), so you'll be able to pass this list to some save() method.
I pushed the demo on GitHub

Related

how do I add a custom layout to a Linear Layout on the click of a button

So I am trying to create a task app, in which, on the click of a button, I want my subtask custom view, which contains a text view, and 2 image views, inside a horizontal linear layout, to be displayed inside a vertical linear layout. The data required for the subtask is taken from a different activity, and then transferred using intents. Also, I need the id for every subtask that is added to be different. I have no idea how to do this. Please help. I couldn't code anything for this. I tried using layout inflater, searched up the net on what to do, but I still have no clue. Please help.
You can user dialog fragment for this and is look effective also
Let me give you link...
dialog fragment
I have done something similar in my project, adding horizontal linear layouts in a vertical linear layout programmatically.
Please check the below code:
View view = View.inflate(getActivity(), R.layout.item_horizontal_layout, null);
Button btnSave = view.findViewById(R.id.btnSaveModule);
layoutCount += 1; // A global value to store added layout counts
btnSave.setTag(layoutCount); // Set the tag on button so that we can use it later
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Access the layout position on button click
Log.d("Layout Position", ":" + (int)btnSave.getTag())
}
});
verticalLL.addView(view); // Add horizontal layout to vertical Linear Layout

Android Java Fragment Button save

I got 2 Fragments. In the first Fragment I got a button.
How is it possible to duplicate the button on the second Fragment when the user click on it.
What do you mean by duplicating a Button? If it means creating a Button with the same text or other layout attribute, you can create a method in the second Fragment, like createButton(String text, int color), to add the button dynamically. When the button is clicked, find the second Fragment, cast it to the class of second Fragment and call the createButton method.

Add multiple clickable zones in a listview row

I want to implement a row for a listview with two click zones with some special requirements:
What I want to implement is something like:
With the following click config:
The red zone links the user profile
The blue zone links the item detail
Clicks over the yellow zone are ignored
When clicking the blue zone all the row is selected (like with a background=?attr/selectableItemBackground)
I have tried several configs but I do not get all the points:
Config A: Add a clicklistener over the blue container and another over the red container, works nice but the full row selected effect when clicking the blue zone is missing.
Config B: Add a clickListener over the full row and another clicklistener over the red container, also works but the clicks over the yellow zone are not ignored.
How can I accomplish that?
Note: Also tried to use the Config B with an empty click listener over the yellow container. But sounds weird to add a clickListener to ignore it, and my real view is more complex than that and I should add a lot of empty clicklisteners. The ideal behavior should be the blue container to propagate its click status to the rowView
You can go with either A or B just with minor addition
A :
Call listview method void setItemsCanFocus(false) so when you click on Blue part, whole row will get focus
B :
Override isEnabled() method in your custom or base adapter and return false for the Yellow part. This will block click events to Yellow part
I hope your error will fix.
Thanks
So A works but you want to get rid the on pressed color ? If so add this in your ListView XML.
<ListView
android:cacheColorHint="#00000000"
android:listSelector="#android:color/transparent"
/>
You should have to implement a layout with Two Sub Layout in which One Contains the Avatar and another contains your data , while in Your Adapter Class You should have to add the tag with Specific Layout id and also add the OnClickListener for that Layout and then while You click the Layout You got the Tag and based on that Tag You are able to handle Your view in ListView Item.

ImageView Onclick Animation

Below is a picture of my app, I am currently using a modified version of this app to show my expandable content. Now my problem is with my ImageView, I currently have 3 layouts, one for the main dialog (with listview), one for the listview title & arrow and one for the item details (item row once expanded). I want to add animation to the ImageView so when you click the image or title textview, the list will expand and animate the change. How can I do this? I cannot get the onClick to work because it doesn't know there are 2 imageviews, it seens only one...
I will assume that your ImageView is this arrow inside your ListView element (because you didn't write it clearly enough).
You probably shouldnt try to attach onClickListener to your ImageView at all (nor to your ListView element title). The good way of implementing what you want you achieve would be to use ListView's onItemClickListener to detect clicks performed on specific items inside your listview, and then expanding appropriate expandable content.

The tags for the GridView items are applying only when they are visible?

I have a GridView which is scrollable: only some of the items will be displayed and only after scrolling down the GridView. We can see the other items. The problem is, I am setting the tags for all the items in the GridView, but by tracing the LogCat I came to know that it is not accepting to set the tags for the non-visible items in the GridView(I mean the items which are inside the grid, but at that time are not on the screen)
Before scrolling:
After scrolling:
Only after scrolling down the other items the tags are applied.
How can I set the tags for all the items of the grid, even if they are on the screen or off the screen?
Your problem is that you set the Tag in the getView method and this method is only called by the framework when the view need to be displayed.
Don't know exactly what you need to do with the view tag, but I think that instead of trying to get the data from a non-displayed view, you must get it from your ImageAdapter (ia.imageid[]).
EDIT:
To answer more preciselly to your question:
How can I set the tags for all the items of the grid, even if they are on the screen or off the screen?
As soon as the view doesn't always exists when it is not displayed: you cannot do it.
I suggest you to explain why you need those tags... may be you can use an alternative solution than view tag to accomplish your final needs.
Anyway, if you really need to have tag on view that aren't displayed yet:
Initialize a view array in onCreate method.
Populate this array with all your views (and set the tag)
modify getView method of your adapter to return the view from your array of view instead of creating the view.
Please note that I don't recommend this solution since it will consume more resources.
Finally myself i got the solution for my question.Thank you for all who gave their valuable suggestions.
Thank you #ben75
i checked the position of present clicked item and then applied the tag so if the user want to select the item which is presently not on the focus he has to scroll the grid and then have to select the item and then only the tag will be applied.

Categories

Resources