@@ -9,6 +9,7 @@ import android.widget.ImageView
99import android.widget.TextView
1010import android.graphics.Color
1111import androidx.constraintlayout.widget.ConstraintLayout
12+ import androidx.recyclerview.widget.RecyclerView
1213import com.chaquo.python.PyException
1314import com.chaquo.python.Python
1415import com.chaquo.python.android.AndroidPlatform
@@ -22,50 +23,21 @@ class MainActivity : AppCompatActivity() {
2223 override fun onCreate (savedInstanceState : Bundle ? ) {
2324 super .onCreate(savedInstanceState)
2425 setContentView(R .layout.activity_main)
26+ val layoutMain = findViewById<ConstraintLayout >(R .id.layout_main)
2527
2628 // Initialize Chaquopy
2729 if (! Python .isStarted()) {
2830 Python .start(AndroidPlatform (this ))
2931 }
3032 val py = Python .getInstance()
31- val createButtonModule = py.getModule(" create_button" )
32- val pyButton = createButtonModule.callAttr(" create_button" , this ).toJava(Button ::class .java)
33- val layoutMain = findViewById<ConstraintLayout >(R .id.layout_main)
34- layoutMain.addView(pyButton)
3533
36- // TODO: Run python module and get button
34+ // val createButtonModule = py.getModule("create_button")
35+ // val pyButton = createButtonModule.callAttr("create_button", this).toJava(Button::class.java)
36+ // layoutMain.addView(pyButton)
3737
38- // Generate UI from Python
39- // val uiLayoutModule = py.getModule("ui_layout")
40- // val layoutJson = uiLayoutModule.callAttr("generate_layout").toString()
41- // val layout = JSONObject(layoutJson)
42- // val widgets = layout.getJSONArray("widgets")
43- //
44- // for (i in 0 until widgets.length()) {
45- // val widget = widgets.getJSONObject(i)
46- // when (widget.getString("type")) {
47- // "Button" -> {
48- // val button = Button(this)
49- // button.text = widget.getJSONObject("properties").getString("text")
50- // button.setTextColor(Color.parseColor(widget.getJSONObject("properties").getString("textColor")))
51- // button.setBackgroundColor(Color.parseColor(widget.getJSONObject("properties").getString("backgroundColor")))
52- //
53- // if (widget.has("eventHandlers") && widget.getJSONObject("eventHandlers").has("onClick")) {
54- // val onClickFunctionName = widget.getJSONObject("eventHandlers").getString("onClick")
55- // val onClickFunction = py.getModule("ui_layout").get(onClickFunctionName)
56- //
57- // button.setOnClickListener {
58- // onClickFunction?.call()
59- // }
60- // }
61- //
62- // // Add button to your layout here
63- // val layoutMain = findViewById<ConstraintLayout>(R.id.layout_main)
64- // layoutMain.addView(button)
65- // }
66- // // Handle other widget types...
67- // }
68- // }
38+ val createRecyclerViewModule = py.getModule(" create_recycler_view" )
39+ val pyRecyclerView = createRecyclerViewModule.callAttr(" create_recycler_view" , this ).toJava(RecyclerView ::class .java)
40+ layoutMain.addView(pyRecyclerView)
6941
7042 // Existing code for displaying plot
7143// val imageView = findViewById<ImageView>(R.id.image_home)
0 commit comments