0

I learn some code in Kotlin and want to translate it into Java. In Kotlin, when creating CustomView, I see that they directly pass ArrayList parameter to class and extends ArrayAdapter like below:

class PostClass (private val userEmail: ArrayList<String>,
                 private val userImage: ArrayList<String>,
                 private val userComment: ArrayList<String>,
                 private val context: Activity) : ArrayAdapter<String>(context, R.layout.custom_view, userEmail)
{ //Do something }

I also try to convert to Java:

class PostClass(ArrayList<String> userEmail, 
ArrayList<String> userImage, 
ArrayList<String> userComment, Activity context) 
extends ArrayAdapter<String> (context, R.layout.custom_view, userEmail) 
{ //Do something }

However, it shows a lot errors. So, can anyone help me to convert it correctly? Thank you.

Vy Tran
  • 25
  • 1
  • 7

1 Answers1

1

In java, you should not define constructor in class declaration. Instead you should create constructor as defined below with class definition.

public class PostClass extends ArrayAdapter<String> {

        public PostClass(ArrayList<String> userEmail,
                  ArrayList<String> userImage,
                  ArrayList<String> userComment,
                  Activity context) {
            super(context, R.layout.custom_view, userEmail);
        }
}

I hope that will help you any way.