I wanted to develop an on screen keyboard similar to the square app (image below)
I would appreciate it if anyone could give me tips on which classes to focus on/ override for this. In particular, how do I associate the button clicks to the number input in the EditText field?
Every Button gets a Tag with the associate value (for example 1). Then, you use the android:onClick-attribute to set all buttons to the same method (input() for example) in the activity.
This method will be called with the clicked view, which you can then use the getTag()-method on to get the corresponding value:
// Will be called for every Button that is clicked
public void input(View v){
Log.v("APP", "Pressed: "+v.getTag());
}
Organize the Buttons in a GridLayout (GridView might also be possible).
Related
A user defined method to change Color of the layout on the basis of button clicked. And, also keep track of what button is clicked.
Like, if a user clicks any button, then the Id of that button should be saved in some variable and then the method will be called to change the colour of a specific button.
The problem is that I know how to change the colour of a button. It can be "user1.setBackgroundColor(Color.RED);"
But don't know how it can be implemented by using a function that takes a single variable...
If you have already decided which colors to use, I think the simplest way is to do layout.setBackgroundColor(getColor(R.color.new_color)); in the click listener of the button.
You can make your activoty implements View.OnClickListener.
So whenever the user click on a button, the method onClick will be called and the view that was clicked will be the argument of that method. You can call view.getId () to find out which button was clicked or you can use view.setBackground (Color.parseColor ("#999999")) to change the button background.
I want to make a custom control in Android.
Actually, I want to extends a EditText with one Button and one TextView. (Like below picture)
My Custom Control Picture
I have not problem with listener. I want just make a custom control that contains 3 controls. (EditText, Button and TextView)
How can I do it?
Create a Linear layout with orientation = horizontal .
Then create an edittext and a button in it .
In java code ,set onClicklistener on button and then get the value of edittext by [edittext].getText().toString() ;
Control means you want to perform any action (a similar action i understand from your explaination) on click of any of the three?
If so, have a specific method which will be called on click of each of the items and alter them according to your choice.
Is this what you meant by user control?
I am trying to attempt the below :
What i am trying to do is whenever a user click on a button, it will add a image to the layout(which the user can scale and move to any position within the layout). The user can repeat this process hence if the user click 6 times on the button, there should be 6 image in the layout.
i have google around, looking for some sample but ain't sure if its the correct one to use. maybe i did not use the correct keyword to search. So far i have seen is endless adapter and RecyclerView but both seen to be mainly for "ListView" type.
Anyone can suggest or share a link/example that i can read up and learn from? It will be a great help.
If you want to add image on button click set on-click listener on it. You need to get how many time the user have clicked the button.
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//get adapter and view
//get image to add
addImage(i); //to desire view
}
});
How do i get a specific view inside of a RecyclerView item? For example I have a floating action button inside of a recyclerview item. The recyclerview card can swipe to trigger an event (new activity) and when the user swipes i am making the fab invisible. I want so that when the user returns back to the activity with the recyclerview, the fab is visible again.
I've tried to implement this a few ways, but for some reason it's taking the fab from the NEXT card/item and placing it on the original card/item that was swiped. This is a problem because the next card might have a different colored fab or no fab at all. What is happening is that it's taking the most recent viewholder item, even if the previous one is the one I want to deal with.
So i need a way to reference the fab in the current item. I'm currently setting it to currentFab = holder.mFab (but again, it's taking the most recent holder item even though it's not the one I pressed on). I need a way to reference the fab in a specific item.
I've tried something similar in the past, I've added the Swipe function in "onBindViewHolder ", Using a Swipe Library.
What I have made is, A CardView, Inside it there are 2 Strings, And a Button, this Button will be invisible according to specific conditions, So because it's inside onBindVewHolder, it was easy to make some edits on the button.
Here's a sample :
holder.Button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.Button.setVisibility(View.GONE);
}
});
Ofcourse this isn't a "fully working code" it's just an example, Plus you didn't put any code that you have tried.
Is there a way to programmatically deselect/wipe whatever the user has selected with the trackball/trackpad?
When I hit the back button on an Activity, the Activity it falls back to has a button that is selected as if the user had used the trackball/pad. I'm not sure what is selected on the previous Activity, but obviously something is. I'd like to programmatically wipe any selection just before the Activity finishes.
Looking through the JavaDoc for View I see a number of focus-related functions.
void clearFocus(); // drop focus from this view.
View findFocus(); // finds a view that is a child of this view that has focus, if any
View focusSearch(int dir); // finds the next view that can take focus in the given direction
void requestFocus
Sounds like findFocus().clearFocus() should do the trick (unless findFocus happens to return null)... you just need a handle to the other activity's View... which shouldn't be too hard if it's your code, or Non Trivial if it isn't.
If it IS your code, it seems like you could just add a clearFocus() to the button's onClickHandler.