Android Like Button Implementation - java

I am trying to make a like button with two states in my app but i am confused on what type of button that is used in android app's like instagram and facebook is it a normal button,image button or a toggle button, i've searched around for this but i haven't gotten any answers, please help

A sleek implementation would be to create a Custom ImageView, which has an object (boolean, int, etc) that maintains it's state. You maintain this state by it's onClickListener associated with the imageview, and set the drawable to be a new image corresponding to it's respective state when triggered.
For example, say you have a "like" button similar to Facebook's. Initially, it has a background drawable of a gray thumb and say our state is a boolean value which is false when gray. When a user clicks on the thumb, state would change to true and the image drawable becomes blue indicating it has been activated. We know to make the drawable the blue version because that state is now "true".
So each click event would swap states, and set the drawable to be a new image based on state. This implies have multiple types of images.
EDIT:
Additionally, this could actually be a button with Text in it and a drawable using drawableLeft , drawableRight , etc... which you change the text color and corresponding drawable on state change via method in your Custom Button implementation

You could make a custom checkbox. When the user presses the checkbox, it changes to the like state. If it's already checked, uncheck the box.
Here is the question I found: Defining custom-checkbox in android

Related

Set The Visibility of The Whole Box

So in my app I have a registration form used to register other users. In my app I have 3 ranks (Admin, Patient, HCP). In the 'New HCP' form I want to hide something that is in my .xml file for the TextView. I am well aware of setVisibilty(View.GONE); but this doesn't work for my options because I have the boxes in a Constraint Layout.
My Question is:
How do I hide the whole box including its contents?
I tried this (but it only hid the contents and left the drawable box behind:
TextView consent_TextView = (TextView) findViewById(R.id.Register_text_Activity_consent);
consent_TextView.setVisibility(View.GONE);
TextView remind_TextView = (TextView) findViewById(R.id.Register_text_Activity_remind);
remind_TextView.setVisibility(View.GONE);
Please remember that I want to change this in Java not XML because if I do it in XML I will hide the box for everyone. Thanks!
As said in the comments, you can get a reference to the box you want to set the visibility either through View#getParent() or you can set its id programatically via View#setId(), bind it and set its visibility.

When I change orientation portrait to landscape, a function is restarted in Android

When I change orientation portrait to landscape (or landscaper to portrait), a function is restarted. I want the function is saved in Android. I'm making a calculator. I don't want operator buttons to be enable before number buttons is clicked. So I made a function that make operator buttons click after number buttons is clicked. However, when I clicked a number to calculate, then change orientation, the operator buttons are not enable. It's supposed to be enable.
I mean, number click -> operator click -> number click -> equals button click -> the result is showed, this is okay. But number click -> change orientation -> operator buttons are not enable.... This is my code
You have two options:
Go to the manifest file and set the orientation of the activity to
either landscape or portrait.
Save some state that your activity holds in a bundle. In OnCreate, the first thing you do is check if the bundle is null (it will be the first time). If it is not then read the bundle (it is the same one you saved) and reset all the states you saved. Save a bundle with your current state information every time at the end of OnCreate. This should fix your problem of resetting states, also allowing you to rotate the device.
This is a widely know concept and you should probably have used a search engine extensively before posting a question. Google is your friend. :)
when you change the orientation of the device your Activity is destroyed and recreated.so you must save the state with onSaveInstanceState()
before the activity is destroyed and than restore it.
moreover if you want to disable orientation change than simply set android:screenOrientation="portrait in you Manifest. read this to learn how to handle runtime changes in Android.

View's contentDescription does not work correctly with TextToSpeech

I work with TextToSpeech and adding "android:contentDescription="#string/custom_button" for ImageButton in xml, reads the value from "#string/custom_button" and adds another "button" in speech.
EG:
"#string/custom_button" = "Custom Button" mapped for mentiond ImageButton, is read as "Custom Button button". There is no text in this button. Id is much different.
How to get rid ot this last "button". It refers to all views read by TextToSpeech.
From my work/research with accessibility, Android automatically adds "button' to the end of talk back for buttons. I could not find any documentation breaking now accessibility to the coding level, but from what i gather they probably add this in the case the developer forgets to indicate in the content description that the the user has clicked a button. There is nothing you can do to remove android's addition of the word button. What you can do is remove it from you custom description so that is only says "Custom". Hope this helps.

Android list selector semitransparent

If this has already been asked, forgive me. But I'm wondering if there is a simple way to adjust the transparency for ListView selection. I know how to change the color, but is there any attribute that allows to adjust the transparency? Or would you have to upload some custom background?
If by transparent you mean see-through, and by ListView selection you mean a single item of the ListView, then its called alpha. The link should show you the info for the XML, but you can also set it using setAlpha(), which is accessible to any View.

isSticky button current state Android

I am developing soft keyboard and I added a toggle button similar to the shift button to my keyboard with option isSticky=true on it. How can I control this sticky button from my code? Or actually is it even possible, since my toggle button loses state each time I change the orientation.
public class SoftKeyboard extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {
And I have a function with onKey to specify the key pressed.
See Handling Orientation Change: http://developer.android.com/guide/topics/resources/runtime-changes.html
I've faced a similar issue. You can create a second drawable, and manually draw the sticky indicator on it. Then load this drawable in your xml or java code - depending on your orientation.

Categories