How can I make this Custom Control and Android - android

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?

Related

Add views dynamically and get value from those views

I need help regarding adding new set of views and get value from those views.
In my example, I want to add 4 TextViews on Button click and open TimePicker from each view click and display new selected time on respective TextView.
Below is screenshot of view.
If these 4 views are fixed you could just create the xml and add them all to a single holder that you set invisible. If you mean by dynamic that it could be either 4 or 99 views, I'd recommend a RecyclerView. Plenty of examples on the internet. If you create a recyclerview with a custom adapter it is very easy to get the respective data per view.
For the future, please add more context to your question like what you've tried, what the result was and why this isn't your expected result. This is a very broad question.
Assuming that on clicking the clock button under the time section (on the right) you would want to set the selected time into the text field. You can simply call view.getParent() on click of the button and from the parent you can get the first child i.e child at 0 and set the text into the text field. This will work provided the button and textfield are within the same layout.

When to use setOnClickListener and setChechedChangeListener in android

I started working with check boxes in android but got confused when to use setCheckedChangelistener and setOnclickListener, pleasae tell me when to select appropriate one and also difference in their implementation.
OnClickListener calls in case, when you click any View (Button, TextView, EditText and other). OnCheckedChangeListener call when View change checked state. It works with Views like (ToggleButton, CheckBox). This Views change and store state after click.
Good luck!
onClickListener is used for widgets like - Buttons , Textview , EditText , LinearLayout , FrameLayout , etc.
onCheckedChangeListener is used for compound button widgets like - CheckBox, RadioButton, Switch, ToggleButton .

Android : How to identify button click in a Listview having more than one button

My custom Listview has more than one button, how can I identify which button has been clicked ? I want to do different things on action of different buttons.
In custom adapder of your ListView you must be creating objects of each button in its getView() method.
Just set the onClickListener on the buttons and perform the action on each buttons in its onClick().
Create local variables for buttons inside getview method and set onClickListener for each button in a row.
Also have a look at this -:
2 Buttons in ListView in android

Create on-screen keyboard (android)

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).

How to display four buttons and a textview in listview in android?

This is my first project in android and I want to display something like this in list view
Any advice is appreciated
You can go through CustomListView example.it can be done easily.
Please go through the Link below
how to customize listview row android
For achieving this layout you should use custom listview for that like it.
A row with one text view and four button mean five object in each row but show only two object one is textview and another is one button out or four button.
If you want to display fourth button then invisible first there button and fourth button in visible state.
If you want to display second button then first, third and fourth button invisible state only second button in visible state.
Fallow this logic in each row.
I hope you got you answer after using this logic.

Categories

Resources