Ich beginne mit der Verwendung DataBinding
Besonderheit. Ich stehe vor einem Problem damit.
Fehler: (21, 9) Fehler: Symbolklasse ContactListActivityBinding kann nicht gefunden werden
build.gradle (Modul: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.letsnurture.ln_202.databindingdemo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
ContactListActivity.java
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.letsnurture.ln_202.databindingdemo.model.Contact;
public class ContactListActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContactListActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_contact_list);
Contact user = new Contact("Chintan Soni", "+91 9876543210");
binding.setContact(user);
// setContentView(R.layout.activity_contact_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@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_contact_list, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
content_contact_list.xml
<?xml version="1.0" encoding="utf-8"?>
<layout 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"
tools:context="com.letsnurture.ln_202.databindingdemo.ContactListActivity"
tools:showIn="@layout/activity_contact_list">
<data>
<variable
name="user"
type="com.letsnurture.ln_202.databindingdemo.model.Contact" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.contactName}"
tools:text="Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.contactNumber}"
tools:text="Number" />
</LinearLayout>
</layout>
activity_contact_list.xml
<?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="com.letsnurture.ln_202.databindingdemo.ContactListActivity">
<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_contact_list" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="https://stackoverflow.com/questions/35126670/@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Kannst du deine Manifest-Inhalte hier posten? weil Ihre Klasse ContactListActivity ist, aber der Fehler ContactListActivityBinding sagt, so dass Sie möglicherweise einen falschen Namen in das Aktivitätstag-Checkout der Manifestdatei eingeben!
– Prithviraj Shiroor
1. Februar 2016 um 9:19 Uhr
Wenn Sie der Meinung sind, dass Ihnen meine Antwort geholfen hat, können Sie das tun Akzeptiere meine Antwort.
– Yennsarah
11. Februar 2016 um 12:38 Uhr
Ihre Klasse sollte ActivityContactListBinding heißen
– Massimo
10. Oktober 2016 um 12:19 Uhr
Stelle sicher das
kapt 'com.android.databinding:compiler:3.0.1'
hat die gleiche Version wie für gradle,classpath 'com.android.tools.build:gradle:3.0.1'
– AbdulMomen عبدالمؤمن
28. März 2018 um 19:09 Uhr
In meinem Fall war es nur eine verwirrende Fehlermeldung. Der gemeldete Fehler war, dass das Symbol für die Bindung nicht gefunden wurde. Das stimmte, aber das zugrunde liegende Problem war, dass ich dort meine Bindung falsch gemacht hatte, sodass sie nicht generiert wurde.
– Matt Robertson
27. August 2019 um 10:40 Uhr