Korrektes zuweisen der FractionCalculator zur DataBinding-Funktionalität
parent
73ea482776
commit
eb6c30f3cd
@ -1,54 +1,52 @@
|
|||||||
package io.n0x.android.java_mot_testing;
|
package io.n0x.android.java_mot_testing;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.databinding.BindingAdapter;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
|
import io.n0x.android.java_mot_testing.databinding.Ex9DataBindingBinding;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
// For debugging
|
||||||
private static final String TAG = MainActivity.class.getName();
|
private static final String TAG = MainActivity.class.getName();
|
||||||
|
// Local calculator instance
|
||||||
|
private FractionCalculator calc;
|
||||||
|
|
||||||
FractionCalculator calc = new FractionCalculator();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.ex9_data_binding);
|
// create calculator instance
|
||||||
Log.d(TAG, "MainActivity started");
|
calc = new FractionCalculator();
|
||||||
|
|
||||||
|
// set a value for testing
|
||||||
|
calc.setEnumResult("0");
|
||||||
|
calc.setDenomResult("0");
|
||||||
|
|
||||||
// Button Listeners
|
// Bind instance of FractionCalculator to view
|
||||||
|
Ex9DataBindingBinding binding = DataBindingUtil.setContentView(this, R.layout.ex9_data_binding);
|
||||||
|
binding.setCalc(calc);
|
||||||
|
|
||||||
|
// Button Listeners
|
||||||
findViewById(R.id.button_add).setOnClickListener(this);
|
findViewById(R.id.button_add).setOnClickListener(this);
|
||||||
|
|
||||||
calc.doStuff();
|
// Log create action
|
||||||
|
Log.d(TAG, "MainActivity started");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (v.getId() == R.id.button_add) {
|
if (v.getId() == R.id.button_add) {
|
||||||
|
|
||||||
|
// works (without using bindings)
|
||||||
TextView textView = findViewById(R.id.txt_enum_result);
|
TextView textView = findViewById(R.id.txt_enum_result);
|
||||||
textView.setText("10");
|
textView.setText("1234");
|
||||||
|
|
||||||
calc.enumResult = 5;
|
// work with DataBinding
|
||||||
calc.denomResult = 6;
|
calc.setDenomLeft("123123123");
|
||||||
|
|
||||||
//calc.setDenomLeft(10);
|
|
||||||
/*
|
|
||||||
enumLeft = 1;
|
|
||||||
denomLeft = 2;
|
|
||||||
enumRight = 3;
|
|
||||||
denomRight = 4;
|
|
||||||
|
|
||||||
|
|
||||||
//*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
|
||||||
tools:context=".MainActivity">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Hello World!"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
Loading…
Reference in New Issue