1

Hi I'm trying to convert this java array to a kotlin array:

String[][] data = {{"May","22"},
                        {"June","45"}};

I tried two ways but my tableView is not showing any record. This is my way number 1:

val mayo: Array<String> = arrayOf("Mayo", "20")
val junio: Array<String> = arrayOf("Junio", "40")
val data2d1 = arrayOf(mayo, junio)

The I pased this array to the adapter of this library: https://github.com/ISchwarz23/SortableTableView

  tableViewSalesPerMonth.dataAdapter = SimpleTableDataAdapter(requireContext(), data2d1)

enter image description here

and nothing happens, there is not data and not errors.

And this the way number 2 I created the next array by using the first array data2d1:

    val data2d2 = mutableListOf<Array<String>>()
    data2d2.addAll(data2d1)

This arrays that I did are wrong? I need something like:

  String[][] data = {{"May","22"},
                            {"June","45"}};

but in kotlin code. Please guys if you have any idea to fix this problem I will appreciate it. Thanks so much.

5
  • var values = arrayOf(arrayOf("may", "33"), arrayOf("jun","32")) may be ok but my table doesn't show anything. Commented Jul 22, 2022 at 0:05
  • This looks correct. Can you elaborate on what goes wrong? Commented Jul 22, 2022 at 1:01
  • The problem seem to be the libray is not showing any record. Commented Jul 22, 2022 at 1:39
  • Are you quite certain you didn't make any typos? There is no possible difference between your code and the Java code you have shown us. Commented Jul 22, 2022 at 1:47
  • No errors bro. I will implement the default tableLayout of android instead of this library Commented Jul 22, 2022 at 2:08

1 Answer 1

1

I think what you are looking for is nested array, your second approach was correct.

val arr: Array<Array<String>> = arrayOf(
    arrayOf("May","222"),
    arrayOf("Hell","222")
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.