Korrektes zuweisen der FractionCalculator zur DataBinding-Funktionalität
parent
73ea482776
commit
eb6c30f3cd
@ -1,54 +1,52 @@
|
||||
package io.n0x.android.java_mot_testing;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
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 {
|
||||
|
||||
// For debugging
|
||||
private static final String TAG = MainActivity.class.getName();
|
||||
|
||||
|
||||
|
||||
FractionCalculator calc = new FractionCalculator();
|
||||
// Local calculator instance
|
||||
private FractionCalculator calc;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.ex9_data_binding);
|
||||
Log.d(TAG, "MainActivity started");
|
||||
// create calculator instance
|
||||
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);
|
||||
|
||||
calc.doStuff();
|
||||
// Log create action
|
||||
Log.d(TAG, "MainActivity started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.button_add) {
|
||||
|
||||
// works (without using bindings)
|
||||
TextView textView = findViewById(R.id.txt_enum_result);
|
||||
textView.setText("10");
|
||||
textView.setText("1234");
|
||||
|
||||
calc.enumResult = 5;
|
||||
calc.denomResult = 6;
|
||||
|
||||
//calc.setDenomLeft(10);
|
||||
/*
|
||||
enumLeft = 1;
|
||||
denomLeft = 2;
|
||||
enumRight = 3;
|
||||
denomRight = 4;
|
||||
|
||||
|
||||
//*/
|
||||
// work with DataBinding
|
||||
calc.setDenomLeft("123123123");
|
||||
}
|
||||
}
|
||||
}
|
@ -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