无法解决符号'绑定'错误

时间:2017-04-28 16:19:40

标签: java android data-binding

所以我最近开始使用绑定,并且我在我的gradle中启用它但是当我尝试使用它时出现错误?我同步了gradle和项目,一切都很好但是当我尝试使用绑定时,它给了我“无法解决符号'绑定'”错误。请帮忙!这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.mike.myapplication.adminScreen"
tools:showIn="@layout/activity_admin_screen">

<EditText
    android:id="@+id/nameEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Name"
    tools:layout_constraintTop_creator="1"
    android:layout_marginStart="37dp"
    android:layout_marginTop="31dp"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<EditText
    android:id="@+id/timeToPrepEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Time To Prepare"
    tools:layout_constraintTop_creator="1"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintRight_toRightOf="@+id/nameEditText"
    android:layout_marginTop="20dp"
    app:layout_constraintTop_toBottomOf="@+id/nameEditText"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="@+id/nameEditText" />

<EditText
    android:id="@+id/descEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Description"
    tools:layout_constraintTop_creator="1"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintRight_toRightOf="@+id/timeToPrepEditText"
    android:layout_marginTop="7dp"
    app:layout_constraintTop_toBottomOf="@+id/timeToPrepEditText"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="@+id/timeToPrepEditText" />

<EditText
    android:id="@+id/priceEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Price"
    tools:layout_constraintTop_creator="1"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintRight_toRightOf="@+id/descEditText"
    android:layout_marginTop="10dp"
    app:layout_constraintTop_toBottomOf="@+id/descEditText"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="@+id/descEditText" />

<Button
    android:id="@+id/addButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Item"
    android:onClick="addButtonClicked"
    tools:layout_constraintTop_creator="1"
    android:layout_marginTop="24dp"
    app:layout_constraintTop_toBottomOf="@+id/priceEditText"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="@+id/priceEditText" />

<Button
    android:id="@+id/deleteButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Delete Item"
    android:onClick="deleteButtonClicked"
    tools:layout_constraintTop_creator="1"
    android:layout_marginTop="15dp"
    app:layout_constraintTop_toBottomOf="@+id/addButton"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="@+id/addButton" />

<Button
    android:id="@+id/databaseButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Display Database"
    android:onClick="dispDatabaseButton"
    tools:layout_constraintTop_creator="1"
    android:layout_marginTop="-79dp"
    app:layout_constraintTop_toBottomOf="@+id/addButton"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="@+id/addButton"
    android:layout_marginLeft="156dp" />

<TextView
    android:id="@+id/myText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="-41dp"
    android:layout_marginStart="15dp"
    android:layout_marginTop="54dp"
    android:onClick="dispDatabaseButton"
    android:text="Results"
    android:textSize="30sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toRightOf="@+id/deleteButton"
    app:layout_constraintTop_toBottomOf="@+id/deleteButton"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintTop_creator="1" />

如何修复错误?

此外,这里是活动的代码,在我的例子中,它不是默认的主要活动,而是AdminScreen。

public class adminScreen extends AppCompatActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin_screen);




}

private void saveToDB() {
    SQLiteDatabase database = new DBSQLiteHelper(this).getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(Menu.MenuItems.COLUMN_NAME, binding.nameEditText.getText().toString());
    values.put(Menu.MenuItems.COLUMN_PREP, binding.timeToPrepEditText.getText().toString());
    values.put(Menu.MenuItems.COLUMN_DESCRIPTION, binding.descEditText.getText().toString());
    values.put(Menu.MenuItems.COLUMN_PRICE, binding.priceEditText.getText().toString());

    long newRowId = database.insert(Menu.MenuItems.TABLE_NAME, null, values);

    Toast.makeText(this, "The new Row Id is " + newRowId, Toast.LENGTH_LONG).show();
     }

}

1 个答案:

答案 0 :(得分:0)

如果您的意思是DataBinding库,那么您应该以这种方式构建布局

<kendo-grid data-k-scope-field="$ctrl.analyticsGrid" data-k-options="$ctrl.gridOptions()" data-k-rebind="$ctrl.dataSource"></kendo-grid>