Change EditText to checkbox on button click in Android - android

Actually i want to change edit text field to check box dynamically on a button click.
initially there is a single button on screen , on clicking a dynamically edit-text is generated, on clicking again the button the edit text converted to checkbox;

I'd suggest you rather use two view elements and show/hide the views.
For example:
Have a LinearLayout that contains 3 elements. The Elements that should be switched, should have the same layout parameters.
A Toggle, a checkbox and a EditTextView.
If the toggle is clicked switch the Visibility for both Views. This is done via mView.setVisibility(View.VISIBLE) or mView.setVisibility(View.INVISIBLE).

Related

Android checkable menu item. Choosing the position of the CheckBox

I have a menu with checkable items. I want to put the CheckBox first and the Text to the right of the CheckBox. Any idea how to do this?
It's not possible to do this using menu items. What you can do, is use a custom Toolbar with a custom ImageView(aligned right) with the image src as the overflow icon (the one with 3 vertical dots). Also create a custom view(let's say checkBoxList) in your layout, which contains the text to the right of checkbox, the way you want it. Keep this checkBoxList aligned to the top right of your parent layout (super easy if you are using ConstraintLayout). Also, keep the visibility of this List to invisible. When overflow icon get's clicked, set the visibility of checkBoxList to visible. Also, have an onClickListener on the parent Layout, where you set the visibility of checkBoxList back to invisible( So that when the user clicks on anywhere outside checkBoxList, it closes).

OnLongClick() blocks the other clicks on the parent view

I have a strange behavior, I use a RecyclerView to display a list.
Each item of this list is composed of a LinearLayout containing 2 TextViews. (It's a classic configuration).
I have an OnClickListener on the LinearLayout and an OnLongClickListener on the second TextView.
The problem is that the OnLongClickListener prevents the "normal clicks" to reach the LinearLayout.
To summarize:
If I click on the first TextView, the Layout is clicked.
If I click on the second TextView, nothing happens.
You can't avoid this situation with your current xml file, you may need to make adjustment
Though if you want it with this design, you have to add OnClickListener to your second text that have OnLongClickListener and call inside it whatever you call on linearView.OnClickListener .
When you clicked on TextView just disable all click of linear layout because at a time one click listener will work.
linearlayout.setClickable(false);
linearlayout.setEnabled(false);

Button Showing a Box

I am trying to make my Button displays a text when clicking on it.
I will give you an example of what I meant :
When clicking a button, a text will appear above the button and pointing to that button.
How can this be done?
You can add a TextView programmatically in the onClick event or add it in the xml, set its visibility to gone or invisible and change it in the onClick event

Android Expanding a single ListView Item

i have a list view with 3 buttons it. the functionality of those button would be that when clicked that single view should expand in height to show a text box. i havent done any code in the CustomAdapter of that listview to provide any reference to it.
What you just described is an ExpandableListView.
EDIT: Also, you can have the TextView's visibility set to "gone" and just become visible when the button is clicked.

Android listview with buttons

I have a listview with custom listitem. I have bunch of textviews in Relative layout. And when I click on listitem it goes to different screen. Now I have added 3 buttons and toggle button to list item and I CAN NOT CLICK THE LIST ITEM. What am I missing :(
set focusable property of all the buttons to false and so that you can click on list and also touch event for all buttons will work
When the user clicks the row, the ListView will look for a widget implementing the Checkable interface. The RelativeLayout does not. An easy way to do that is simply to create your own CheckableRelativeLayout class. See http://www.marvinlabs.com/2010/10/custom-listview-ability-check-items/ for a full tutorial with code.
Also, the buttons and other items in your row layout should not be focusable. You can see other SO questions: Android Row becomes Unclickable with Button

Categories

Resources