Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Unable to get it working with Kotlin #43

Open
ka05 opened this issue Jun 8, 2018 · 3 comments
Open

Unable to get it working with Kotlin #43

ka05 opened this issue Jun 8, 2018 · 3 comments

Comments

@ka05
Copy link

ka05 commented Jun 8, 2018

Im using kotlin and have been following the guide in the readme.

Problem 1
I came across the section below in the readme and i cannot get it to work.

class BookCell(item: Book) : SimpleCell<Book>(item) {
  override fun getLayoutRes(): Int {
    return R.layout.cell_book
  }

  override fun onBindViewHolder(holder: SimpleViewHolder, position: Int, context: Context, payload: Any) {
    holder.textView.text = item.title
  }
}

Android Studio does not recognize textView in this line:
holder.textView.text = item.title

I did create the layout file and have a textView with the matching Id so im not sure whats going on.

I was under the impression that maybe you were doing some sort of compile time generation to generate the holder to be used based off of the layout file, but that cant be because com.jaychang.srv.kae.SimpleCell uses SimpleViewHolder explicitly which only extends com.jaychang.srv.SimpleViewHolder.

Problem 2
Cant create list of SimpleCell type in kotlin that is shown in the Multiple Types section of the readme.

List<Book> books = DataUtils.getBooks();
List<Ad> ads = DataUtils.getAds();
List<SimpleCell> cells = new ArrayList<>();

My version, In Kotlin

val books:MutableList<Book> = DataUtils.getBooks();
val ads:MutableList<Ad> = DataUtils.getAds();
val cells:MutableList<SimpleCell> = mutableListOf()

Android Studio is complaining about SimpleCell in the list declaration ( MutableList<SimpleCell> ) stating that I must add the Type argument.

One type argument expected for class SimpleCell<T>

I am very confused and would greatly appreciate it if you could provide a more detailed guide for using this library with kotlin and perhaps several kotlin example activities in the source.

I suppose for the time being i can write this in java but that also means other areas of my app that are already in kotlin will have to be converted back to java, which is a bummer. :(

@jaychang0917
Copy link
Owner

jaychang0917 commented Jun 8, 2018

Problem 1:
Have you added kotlin android extension plugin?

Problem 2:
SimpleCell<T> is a parameterized type, so you should write val cells:MutableList<SimpleCel<*>> = mutableListOf().

@ka05
Copy link
Author

ka05 commented Jun 8, 2018

@jaychang0917, Yes i am using the kotlin android extension plugin. I even tried cleaning and building to make sure but no dice.

Correct me if Im wrong but doesn't that plugin only work when referencing views directly?
like below:

textView.text = item.title

The example show this though which I haven't seen work like this anywhere else:

holder.textView.text = item.title

Perhaps I need to just remove holder? Wouldn't that cause the holder pattern to break though?

@jaychang0917
Copy link
Owner

Make sure you added

androidExtensions {
    experimental = true
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants