https://kotlinlang.org logo
#android
Title
# android
b

bodo

06/18/2017, 8:46 AM
Hi. I am using "kotlin-android-extensions" in my apps. Now i focused a problem when the layout file is declared i another module, e.g. MODULE-A -> fragment_recyclerview MODULE-B -> Fragment which uses this layout file The import ist made correct (in Fragment of Module B): import kotlinx.android.synthetic.main.fragment_recyclerview.contentView But if i want to run the app the comiler throws this error: Unresolved reference: fragment_recyclerview Unresolved reference: contentView So my question: Is it not possible to access layout ids from layout files of different modules with android extensions?
n

nikaoto

06/18/2017, 9:11 AM
bodo: Yes, it is possible, but it'd be great if you could provide some more details about the problem. Maybe give us the full stack trace or a bigger snippet of your code?
b

bodo

06/18/2017, 9:14 AM
@nikaoto of course
Copy code
@FragmentWithArgs class MovieFragment : FragmentRv<MoviePresenter, ListDelegationAdapter<List<IScreenItem>>, MovieViewState, MovieView>(),  MovieView {

  @Arg var movieId: Int = 1

  override fun onAttach(context: Context?) {
    MovieFragmentBuilder.injectArguments(this)
    super.onAttach(context)
  }

  override fun loadData(): Observable<Int> = Observable.just(movieId)

  override fun content(screen: Screen) {
    super.content(screen)

    contentView.setHasFixedSize(true)
    activity.supportStartPostponedEnterTransition()
  }

  override fun error(error: Throwable) {
    super.error(error)

    activity.supportStartPostponedEnterTransition()
  }
}
the error is thrown when contentView.setHasFixedSize(true) is compiled
because the layout file is in a different module
here is the stacktrace:
Copy code
:features:movie:compileDebugKotlin
e: /Users/bodo/Develop/private/AllAboutMovies/features/movie/src/main/java/com/christianbahl/allaboutmovies/movie/MovieFragment.kt: (11, 39): Unresolved reference: fragment_recyclerview
e: /Users/bodo/Develop/private/AllAboutMovies/features/movie/src/main/java/com/christianbahl/allaboutmovies/movie/MovieFragment.kt: (30, 5): Unresolved reference: contentView
n

nikaoto

06/18/2017, 9:16 AM
You need to declare an internal contentView if I'm not mistaken.
Sorry, no. Actually, you could try doing the import kotlinx.android.synthetic... on each class that is using the contentView or recyclerview
b

bodo

06/18/2017, 9:18 AM
Yes I did this in the extended frament like this:
val recyclerView: RecyclerView by lazy { contentView }
this is not working. the fragment above has this import:
import kotlinx.android.synthetic.main.fragment_recyclerview.contentView
n

nikaoto

06/18/2017, 9:25 AM
Seems I'm having a hard time wrapping my mind around this. We can wait for someone more experienced to look at the problem :S
r

radityagumay

06/18/2017, 10:37 AM
Did you put the code in git? So I can reproduce it
15 Views