I'm trying to make a To Do List app. When the screen rotates, all of the dynamically added textviews get removed. The textviews get added into a LinearLayout within a linearlayout, right above the add button.
MainActivity.Java
public class MainActivity extends Activity {
private LinearLayout mLayout;
private LinearLayout ListItems;
static final String counter_value = "int_value";
static final String toDoList_value = "toDolist";
private EditText mEditText;
private Button mButton;
private int counter;
private ArrayList<String> toDoList;
private ArrayList<String> keys;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//This makes it so that the keyboard appears only after you tap the EditText. Stackoverflow question by fixEdd Android on-screen keyboard auto popping up
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
// end code
if (toDoList != null){
System.out.println("Success!");
for(int i = 0; i< toDoList.size(); i++){
System.out.println(toDoList.get(i));
ListItems.addView(createNewTextView(toDoList.get(i)));
}
}
else{
System.out.println("Nope!");
toDoList = new ArrayList<String>();
}
counter = 1;
mLayout = (LinearLayout) findViewById(R.id.linearLayout);
ListItems = (LinearLayout) findViewById(R.id.listItems);
mEditText = (EditText) findViewById(R.id.editText);
mButton = (Button) findViewById(R.id.button);
mButton.setOnClickListener(onClick());
TextView textView = new TextView(this);
textView.setText("New text");
}
private View.OnClickListener onClick() {
return new View.OnClickListener() {
#Override
public void onClick(View v) {
ListItems.addView(createNewTextView(mEditText.getText().toString()));
}
};
}
private TextView createNewTextView(String text) {
final RadioGroup.LayoutParams lparams = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
final TextView textView = new TextView(this);
textView.setLayoutParams(lparams);
textView.setFreezesText(true);
textView.setText(counter + ":" + text);
textView.setId(counter);
System.out.println(textView.getId());
toDoList.add(text);
counter++;
return textView;
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
counter = savedInstanceState.getInt(counter_value);
toDoList = savedInstanceState.getStringArrayList("key");
//REad values from the savedInstanceState" -object and put them in your textview
}
#Override
protected void onSaveInstanceState(Bundle outState){
// Save the values you need from your textview into "outSTate" -object
// outState.putParcelableArrayList("key", toDoList);
outState.putInt(counter_value, counter);
outState.putStringArrayList("key", toDoList);
super.onSaveInstanceState(outState);
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/listItems"></LinearLayout>
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add+"
/>
</LinearLayout>
Also I am not sure if readding the views is the best way to do this. It seems like it's a waste of operations. Is there a way to just keep the textviews in place?
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
counter = savedInstanceState.getInt(counter_value);
toDoList = savedInstanceState.getStringArrayList("key");
// Add this for-loop to restoring your list
for(String str : toDoList){
ListItems.addView(createNewTextView(str));
}
}
However, in my opinion, this is not a good approach. It's better to use a ListView
It's better if you implement your To Do list using a ListView with its Adapter. There are plenty of tutorials on the web, start for example from this one.
Related
My question is fairly simple. I currently have Radiobuttons that look like this :
I would like to set the text to be below the image (and eventually set it as bold when the button is clicked).
My XML file looks like this :
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioGroup
android:id="#+id/radio_group_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
</HorizontalScrollView>
And part of my Java code :
RadioGroup categoryGroup = view.findViewById(R.id.radio_group_category);
for(int i=0; i<categories.size(); i++) {
final String name = categories.get(i).name;
final int resource = categories.get(i).resource;
final RadioButton button = new RadioButton(getContext());
button.setButtonDrawable(resource);
button.setText(name);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Set text as bold (I'll add some logic too)
}
});
categoryGroup.addView(button);
}
Try this :
RadioGroup categoryGroup = view.findViewById(R.id.radio_group_category);
for(int i=0; i<categories.size(); i++) {
final String name = categories.get(i).name;
final int resource = categories.get(i).resource;
final RadioButton button = new RadioButton(getContext());
Drawable drawable = getResources().getDrawable(resource);
button.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
button.setButtonDrawable(null);
button.setText(name);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
button.setText(Html.fromHtml("<h2>"+button.getText().toString()+"</h2>",
Html.FROM_HTML_MODE_COMPACT));
} else {
button.setText(Html.fromHtml("<h2>"+button.getText().toString()+"</h2>"));
}
}
});
categoryGroup.addView(button);
}
Try this
public class MainActivity extends AppCompatActivity {
LinearLayout linearLayout;
RadioGroup radioGroup;
RadioButton radioButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
linearLayout = new LinearLayout(getApplicationContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
radioGroup = new RadioGroup(getApplicationContext());
linearLayout.addView(radioGroup);
for (int i = 0; i<5 ;i++){
radioButton = new RadioButton(getApplicationContext());
radioButton.setText(String.valueOf(i));
radioGroup.addView(radioButton);
}
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params1.setMargins(3, 0, 3, 5);
getWindow().addContentView(linearLayout, params1);
}
}
This worked for me check this out
this is how it looks.
I keep getting an error in regards to the toolbar I have in my code, If i take the code out it works fine but it was working fine before i added in a separate line for a database so i'm really confused to why this isn't working. I've added in my XML at the bottom also.
private static final String TAG = MainActivity.class.getSimpleName();
private ArrayList<Item>list = new ArrayList<Item>();
private ItemAdapter adapter;
private RecyclerView recyclerView;
private AlertDialog dialog;
#Override
***protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);***
FloatingActionButton fab = (FloatingActionButton)
findViewById(R.id.fab);
fetchRecords();
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater inflater = getLayoutInflater();
View mView1 = inflater.inflate(R.layout.activity_add,null);
final EditText input_name = (EditText)
mView1.findViewById(R.id.Name);
final EditText input_age = (EditText)
mView1.findViewById(R.id.Age);
final EditText input_weight = (EditText)
mView1.findViewById(R.id.Weight);
final EditText input_height = (EditText)
mView1.findViewById(R.id.Height);
final EditText input_reach = (EditText)
mView1.findViewById(R.id.Reach);
final Button btnSave = (Button)
mView1.findViewById(R.id.btnSave);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(mView1).setTitle("Add new Record")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String name = input_name.getText().toString();
String age = input_age.getText().toString();
String weight = input_weight.getText().toString();
String height = input_height.getText().toString();
String reach = input_reach.getText().toString();
if (name.equals("") && age.equals("") && weight.equals("") && height.equals("")&& reach.equals("")){
Snackbar.make(view,"Field incomplete",Snackbar.LENGTH_SHORT).show();
}else {
Save(name,age,name,height,reach);
dialog.dismiss();
Snackbar.make(view,"Saving",Snackbar.LENGTH_SHORT).show();
}
}
});
dialog = builder.create();
dialog.show();
}
});
}
public void fetchRecords() {
recyclerView = (RecyclerView) findViewById(R.id.recycler);
adapter = new ItemAdapter(this,list);
LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
list.clear();
Functions functions = new Functions(MainActivity.this);
ArrayList<Item>data = functions.getAllRecords();
if (data.size()>0){
for (int i = 0; i<data.size(); i++){
int id = data.get(i).getId();
String namel = data.get(i).getName();
String agel = data.get(i).getAge();
String weightl = data.get(i).getWeight();
String heightl = data.get(i).getHeight();
String reachl = data.get(i).getHeight();
Item item = new Item();
item.setId(id);
item.setName(namel);
item.setAge(agel);
item.setWeight(weightl);
item.setHeight(heightl);
item.setReach(reachl);
list.add(item);
}adapter.notifyDataSetChanged();
}else {
Toast.makeText(MainActivity.this, "No Records found.", Toast.LENGTH_SHORT).show();
}
}
private void Save(String name, String age, String weight, String height, String reach) {
Functions functions = new Functions(MainActivity.this);
Item item = new Item();
item.setName(name);
item.setAge(age);
item.setWeight(weight);
item.setHeight(height);
item.setHeight(reach);
functions.Insert(item);
Toast.makeText(MainActivity.this, "Saved...", Toast.LENGTH_SHORT).show();
fetchRecords();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Layout file
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="android.wit.dale.fighterstudio.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="bottom|end"
android:layout_marginBottom="65dp"
android:src="#android:drawable/ic_input_add" />
</android.support.design.widget.CoordinatorLayout>
RUN TIME ERROR
In your styles.xml use Theme.AppCompat.Light.NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
........
</style>
use
androidx.appcompat.widget.Toolbar
instead of
Toolbar
in your layout. Also, make sure that in your styles you use Theme.AppCompat.Light.NoActionBar
I need you help.
I made a small application, and it is necessary to bring "tiles" button.
Now i have an array with letters
<string-array name="let_terms">
<item>A</item>
<item>B</item>
<item>C</item>
......
And then programmatically output the button with these letters:
public class letterms extends AppCompatActivity {
String[] mArray;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.letterms);
int length =0;
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
length =getResources().getStringArray(R.array.let_terms).length;
mArray = getResources().getStringArray(R.array.let_terms);
final LinearLayout linearLayout=(LinearLayout)findViewById(R.id.buttonlayout);
for(int i=0;i<length;i++){
final String nazv = mArray[i];
final String[] splittedItem = nazv.split(":");
Button button=new Button(this);
button.setId(i);
button.setWidth(20);
button.setLayoutParams(params);
button.setText(splittedItem[0]);
button.setTextColor(0xFF2C85A6);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent is = new Intent(getApplicationContext(), termin_full.class);
is.putExtra("fVariableName", nazv);
startActivity(is);
}
});
linearLayout.addView(button);
}
}
}
In XML:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonlayout">
</LinearLayout>
All right, go bat buttons in a row, and I would like to carry on a new line when it reaches the end of the screen. How to tile...
Where can I see an example of such an implementation?
Use vertical LinearLayout in XML. Then programmatically create horizontal LinearLayout and add buttons in horizontal layout. For each line, create and add new horizontal layout.
XML:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/buttonlayout">
</LinearLayout>
ACTIVITY:
public class letterms extends AppCompatActivity {
String[] mArray;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.letterms);
int length =0;
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
length =getResources().getStringArray(R.array.let_terms).length;
mArray = getResources().getStringArray(R.array.let_terms);
final LinearLayout verticalLayout= LinearLayout)findViewById(R.id.buttonlayout);
int verticalWidth = verticalLayout.getWidth();
int numberOfButtonsPerLine = (verticalWidth/buttonWidth);
int numberOfLines = (length/numberOfButtonsPerLine) + 1;
for(int i=0;i<length;){
LinearLayout newLine = new LinearLayout(this);
newLine.setLayoutParams(params);
newLine.setOrientation(LinearLayout.HORIZONTAL);
for(int j=0;j<numberOfLines;j++){
final String nazv = mArray[i];
final String[] splittedItem = nazv.split(":");
Button button=new Button(this);
button.setId(i);
button.setWidth(20);
button.setLayoutParams(params);
button.setText(splittedItem[0]);
button.setTextColor(0xFF2C85A6);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent is = new Intent(getApplicationContext(), termin_full.class);
is.putExtra("fVariableName", nazv);
startActivity(is);
}
});
newLine.addView(button);
i++;
if(i>=length) {
break;
}
}
verticalLayout.addView(newLine);
}
}
}
GridLayout is the best option for your scenario. By GridLayout you don't need to calculate the width of the screen.
You can find the guide for it on the link below.
GridView guide
I have a EditText view :
<EditText
android:id="#+id/vorgabezeit"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="#0277BD"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLength="5"
android:textAlignment="textEnd"
android:textColor="#ffffff"
android:textCursorDrawable="#null"
android:textStyle="bold"
/>
The value entered in this EditText I would like to use it in an math operation.
Before I had fixed values :
public void submitOrder(View view) {
displayPrice((procente / myEditNum) * mitarbeiter);
}
where variables were defined as :
int procente = 120;
int mitarbeiter = 1;
Now, I searched for hours on the web how to take that value entered in EditText and use id further, and this is as close as I got :
public class MainActivity extends AppCompatActivity {
int procente = 120;
int mitarbeiter = 1;
EditText myEdit = (EditText) findViewById(R.id.vorgabezeit);
String myEditValue = myEdit.getText().toString();
double myEditNum = Double.parseDouble(myEditValue);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void submitOrder(View view) {
displayPrice((procente / myEditNum) * mitarbeiter);
}
}
The application crashes from the start.
Thank you for your patience and help.
Best regards,
Robert
First you need to post the LogCat when you are having a crash.
Second You can not call findViewById until after setContentView is called. You should to initialize your edit text in onCreate.
// Initialize values in onCreate after setContentView
EditText myEdit;
String myEditValue;
double myEditNum;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myEdit = (EditText) findViewById(R.id.vorgabezeit);
myEditValue = myEdit.getText().toString();
myEditNum = Double.parseDouble(myEditValue);
}
Make sure you add android:inputType="number" to your EditText on the xml to ensure the user can ONLY type numbers on it, then :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.button)
.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
displayPrice((procente / Double.parseDouble(((EditText) findViewById(R.id.vorgabezeit))
.getText().toString())) * mitarbeiter);
}
});
}
btw your code crashes because you called findviewById before setting the content view to the activity so basically it searches on a non-existing layout and your edit text and button become null because of it
What about getText(). I added button, since you have to get text after some user action, not right after onCreate event.
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton = (Button)findViewById(R.id.button);
mEdit = (EditText)findViewById(R.id.vorgabezeit);
mButton.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
Log.v("EditText", mEdit.getText().toString());
}
});
}
When making a custom component for Android, as far as I understood, I need:
one xml file with the layout for the component;
one java class.
Tried to make one, just for practice. Use two progressbars and one button in the XML, and create the class, than tried out in my main activity, worked fine.
But now I'm loking how to set OnClickListener on my button through the activity, and in this part I'm lost.
My loading_button.xml:
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:progress="0"
android:id="#+id/pg_top" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btn_ok"
android:background="#color/colorPrimary"
android:textColor="#ffffff"
android:layout_below="#+id/pg_top"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="5dp"
android:progress="0"
android:id="#+id/pg_bottom"
android:layout_below="#+id/btn_ok"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</merge>
Here the LoadingButton.java:
public class LoadingButton extends RelativeLayout{
private ProgressBar pbTop;
private ProgressBar pbBottom;
private Button btnOk;
private int pbTopProgress = 0;
private int pbBottomProgress = 0;
public LoadingButton(Context context, AttributeSet attrs) {
super(context, attrs);
View view = View.inflate(context, R.layout.loading_button, this);
btnOk = (Button) view.findViewById(R.id.btn_ok);
pbTop = (ProgressBar) view.findViewById(R.id.pg_top);
pbBottom = (ProgressBar) view.findViewById(R.id.pg_bottom);
btnOk.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Doing stuff ok
}
});
}// LoadingButton
}
The setOnClickListener in the class works, but how can I set it from my main activity?
MainActivity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// My new component (it's id in activity_main.xml is 'lb')
LoadingButton lb = (LoadingButton) findViewById(R.id.lb);
// QUESTION - how to make something like this with btnOk:
lb.btnOkSetOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Do stuff
}
});
}
}
If this is possible, how?
If not, what is the right approach to make a custom component and set clickListeners on specific element of this component?
Best approach to handle all view click in LoadingButton (For custom view). And create interface.
public class LoadingButton extends RelativeLayout {
public interface OnLoadingButtonClickListener{
void onLoadingButtonClickListener();
}
private ProgressBar pbTop;
private ProgressBar pbBottom;
private Button btnOk;
private int pbTopProgress = 0;
private int pbBottomProgress = 0;
private OnLoadingButtonClickListener mONOnLoadingButtonClickListener;
public LoadingButton(Context context, AttributeSet attrs) {
super(context, attrs);
View view = View.inflate(context, R.layout.loading_button, this);
btnOk = (Button) view.findViewById(R.id.btn_ok);
pbTop = (ProgressBar) view.findViewById(R.id.pg_top);
pbBottom = (ProgressBar) view.findViewById(R.id.pg_bottom);
btnOk.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(mONOnLoadingButtonClickListener != null){
mONOnLoadingButtonClickListener.onLoadingButtonClickListener();
}
}
});
}// LoadingButton
public void setOnLoadingClickListener(OnLoadingButtonClickListener onLoadingClickListener){
mONOnLoadingButtonClickListener = onLoadingClickListener;
}
}
And implement OnLoadingButtonClickListener in your activity.
public class MainActivity extends AppCompatActivity implements LoadingButton.OnLoadingButtonClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// My new component (it's id in activity_main.xml is 'lb')
LoadingButton lb = (LoadingButton) findViewById(R.id.lb);
lb.setOnLoadingClickListener(this);
}
#Override
public void onLoadingButtonClickListener() {
//do your stuff on ok button click
}
}
Override setOnClickListener(OnClickListener listener) in your custom Java class. Inside it, write:
btnOk.setOnClickListener(listener);
where listener is an argument of your custom view's setOnClickListener() function.
That will make your whole view clickable and click on your button will be performed. Of couse add android:clickable="true" to your custom view's root layout.
In the component
class Example #JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0,
defStyleRes: Int = 0) : ConstraintLayout(context, attrs, defStyle) {
var clickListener: () -> Unit = { }
init { }
private fun initListeners() {
binding.button.onClick {
clickListener()
}
}
In the activity / fragment
component.clickListener = { }
And the best part, you can send data on the component and receive it in the landa