2017-12-18 22 views
1

私は何か明白でないかもしれないと思うのですが、バインディングは私のtextview idにアクセスできません。例えば。Androidのデータバインディングでシンボルを解決できない(gradle 3.0.1)

binding.myText.setText( "text here"); >記号 'MYTEXT'


MainActivity.java

public class MainActivity extends AppCompatActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); 
     binding.myText.setText("test"); 
    } 
} 
を解決することはできません


activity_main.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"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/myText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent"/> 
    </android.support.constraint.ConstraintLayout> 
</layout> 

編集


アプリ/ build.gradle プラグインを適用する: 'com.android.application'

android { 
    compileSdkVersion 26 
    defaultConfig { 
     applicationId "com.example.francoismarais.myapplication" 
     minSdkVersion 15 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    dataBinding { 
     enabled = true 
    } 
} 

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 

    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
} 

build.gradle(ルート)

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 

    repositories { 
     google() 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:3.0.1' 


     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     google() 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 
+1

クリーン/リビルドを試しましたか? – MHogge

+0

私は、キャッシュを無効にして再起動してみましょう。私はまた、私のgradleファイルを追加、maby何かが不足している:| – Francois

+1

申し訳ありませんが、私はキャッシュを無効にして再起動しました。それは現在の状態になっているようです:)明白な質問を申し訳ありません。 – Francois

答えて

0
dependencies { 
    classpath 'com.android.tools.build:gradle:3.0.0' 

    // NOTE: Do not place your application dependencies here; they belong 
    // in the individual module build.gradle files 
    } 

変更gradle:3.0.1gradle:3.0.0

+1

キャッシュを無効にして再起動しました:) – Francois

関連する問題