Editable List with checkbox - android

I want to create a editable list with checkboxes for creating todo (just like checkboxes in Google Keep). Is there a control to achieve this ?
Edit: See the Image of Google Keep List.

There is no editable Checkbox provided by android what you can do is set listeners on your checkboxes, and then have to capture the events like when checkbox is checked and when is it unchecked to make your editexts work the way you want.A sample way to start is :
CheckBox someCheckBox= (CheckBox) findViewById (R.id.someID);
someCheckBox.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
//CODE TO MAKE THE EDITTEXT ENABLED
}
else
//CODE TO MAKE THE EDITTEXT DISABLED
}
});
However there are other ways too,to achieve this task, but you can kick off with this right away. Hope it helps.

Related

Android how to show hidden item only for one row on click

im trying to create a listView, that has an Button item on it.
I want to make this button clickable, so I did something like this code in Adapter, getView:
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("_myButton_Log", "ShowOnClick");
}
});
And now im trying to change the visibility parameter for my textView:
TextView myDesc = row.findViewById(R.id.my_desc);
myDesc.setVisibility(convertView.GONE);
I want to show this textView in only one row, after click this button.
Now I make that, the button is clickable for each rows but as you can see it's show only the Log. Im a newbie in the ListViews and buttons on it and im trying to get knowledge how to make it work, but for now I cannot find any help...
So im begging here for some help! :)
Anyway if you want me to use the OnItemClickListener it's not possible because im using it for another way.
Ok I found out an response for my question.
Everyone with this problem - just need to make a simple action for a button in list view in your adapter like:
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView myPrice = row.findViewById(R.id.price);
Button myButton = row.findViewById(R.id.button);
myPrice.setVisibility(convertView.VISIBLE);
myButton.setVisibility(convertView.GONE);
}
});

How to clear checkboxes when reset button is clicked

In my project I have a number of checkboxes in a linear layout. When running the project by default all checkboxes are unchecked and I need to check some checkboxes. Below the checkboxes there is a reset button. When the reset button is clicked all the checkboxes are unchecked. How do I do this? Please help.
Call this in onClick()of Reset button.
if (checkBox1.isChecked()) {
checkBox1.setChecked(false);
}
if (checkBox2.isChecked()) {
checkBox2.setChecked(false);
}
.
.
.
and so on
To Uncheck all checked CheackBoxes keep references of the checked Checkboxes in ListView/Array and when reset button is clicked mark them as unchecked,
ListView <CheckBox> selectedcheckBox = new ListView<CheckBox> ();
when Checkbox is Checked---
selectedcheckBox.add(referanceofckeckbox).
now when reset button is clicked
public void onclick(View v){
for(CheckBox cb : selectedcheckBox){
cb.setChecked(false);
}
}
Hope it help.
if (checkBox.isChecked()) {
checkBox.toggle();
}
use this for all the checkboxes used.
For me it worked like this:
CheckBox checkBox = (CheckBox) findViewById(R.id.check_box);
checkBox.setChecked(false);
I see this is old stuff, but has no valid answer so maybe this one helps anyone.
jQuery + CSS selectors work very well for this. If you just want to uncheck all those checkboxes that are checked you just need the following code:
$('[type=checkbox]:checked').prop('checked', false);
While if you want to toggle all you can add variable to hold the checked status like this:
var isChecked = $('[type=checkbox]').is(':checked');
$('[type=checkbox]').prop('checked', !isChecked);

How to enable and disable my edit box on the checkbox clilck event

I am facing problem with enabling an edittext box at initialisation. I have disabled my editbox like so: text_edit.setFocusable(false);
Later, I want to enable the textbox via the click of a checkbox.
The textbox is not being enabled, here is my click event code:
if(((CheckBox) v).isChecked()) {
Toast.makeText(User_name_search .this, "Selected", Toast.LENGTH_SHORT).show();
text_edit.setFocusable(false);
//checkbox.setChecked(false);
} else {
Toast.makeText(User_name_search .this, "Not Selected", Toast.LENGTH_SHORT).show();
text_edit.setFocusable(true);
}
What am I doing wrong?
Since you want to enable/disable the EditText, you should consider use the setEnabled(boolean x) method as described here: http://developer.android.com/reference/android/widget/TextView.html#setEnabled%28boolean%29 (EditText extends TextView).
Hope this helps!
You should use setOnClickListener or setOnCheckedChangeListener for the checkbox, and when somebody clicks, you should change setfocusable.
You have to do the following
Checkbox c1;
EditText e1;
click on check box c1 if
if(c1.isChecked==true)
{
e1.setEnabled(true);
}
else
{
e1.setEnabled(false);
}
In the click listener of the checkbox set the enabled property of the edittext to true. So if checkAbove is your checkbox and textAbove is your editText, the code will look like this..
checkAbove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CheckBox temp = (CheckBox)view;
if (temp.isChecked()){
textAbove.setEnabled(true);
}else {
textAbove.setEnabled(false);
}
}
});
Also put
android:editable = "false"
for the textAbove view in the xml.

android: Replace the checkbox in CheckedTextView by an button

By default, there is a checkedbox in CheckedTextView, but now I want to replace it by an button.
I have tried to setCheckMarkDrawable which does exactly what I want it look like.
But now the problem is how can I add a listener to this. I want this button to remove current item in the ListView. How can I achieve this?
You could set your button by calling a ressource id like that:
setCheckMarkDrawable (R.id.myListButton);
Then set your listener on that button with:
(Button)findViewById(R.id.myListButton)
.setOnclickListener(new onClickListener()
{
public void onClick(View v)
{
//Do somethting here
}
});

Layout in android

I have three buttons in one activity.when each of the button is clicked ,different layout should be shown with in the same activity.for example if first button is clicked,edit boxes and button should be shown.if second buttojn is clicked listview should be shown etc..
Define different layout files for each layout.
Then after each click event have the intent call this particular activity recalled.
Have setContentView() called conditionally ie determining the particular clickevent and vice versa.
This you can do if you want complete activity to be layuot in diffrent manner. Otherwise if you want some widgets to be displayed on button click then it is pretty easy to show them on click event.
You might wanna consider a "TabWidget" for this. It actually does what you need.
A sample tutorial here.
Why don't you just include the all the layout elements in your single layout, then use the setVisibility attribute to turn them on and off, depending on which button is pressed.
Something like this pseudo code:
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
view1.setVisibility(View.GONE);
view2.setVisibility(View.GONE);
view2.setVisibility(View.VISIBLE);
}
});
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
view1.setVisibility(View.VISIBLE);
view2.setVisibility(View.GONE);
view2.setVisibility(View.GONE);
}
});

Categories

Resources