Mercurial > dwindows
comparison android/DWindows.kt @ 2561:f28d7d0ca5ed
Android: Attempt at implementing updating the container after insertion.
I am trying to use notifyDataSetChanged() in our DWContainerAdapter class.
This is called via _dw_container_refresh() and containerRefresh()
however it does not seem to be working yet.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 18 May 2021 22:48:33 +0000 |
parents | 3da35cd91ca7 |
children | 11411f103d27 |
comparison
equal
deleted
inserted
replaced
2560:3da35cd91ca7 | 2561:f28d7d0ca5ed |
---|---|
640 override fun getItemId(position: Int): Long { | 640 override fun getItemId(position: Int): Long { |
641 return position.toLong() | 641 return position.toLong() |
642 } | 642 } |
643 | 643 |
644 override fun getView(position: Int, view: View?, parent: ViewGroup): View { | 644 override fun getView(position: Int, view: View?, parent: ViewGroup): View { |
645 val rowView = ConstraintLayout(context) | 645 var rowView: ConstraintLayout? = view as ConstraintLayout |
646 val set = ConstraintSet() | 646 |
647 | 647 // If the view passed in is null we need to create the layout |
648 // Every container at least has an icon and text | 648 if(rowView == null) { |
649 val imageview = ImageView(context) | 649 rowView = ConstraintLayout(context) |
650 val textview = TextView(context) | 650 val set = ConstraintSet() |
651 | 651 // Every container at least has an icon and text |
652 if(model.numberOfColumns() > 1 && model.numberOfRows() > position) { | 652 val imageview = ImageView(context) |
653 val first = model.getRowAndColumn(position, 0) | 653 val textview = TextView(context) |
654 val second = model.getRowAndColumn(position, 1) | 654 |
655 | 655 if (model.numberOfColumns() > 1 && model.numberOfRows() > position) { |
656 if(first is Drawable) { | 656 val first = model.getRowAndColumn(position, 0) |
657 imageview.setImageDrawable(first) | 657 val second = model.getRowAndColumn(position, 1) |
658 } | 658 |
659 if(second is String) { | 659 if (first is Drawable) { |
660 textview.text = second | 660 imageview.setImageDrawable(first) |
661 } | 661 } |
662 } | 662 if (second is String) { |
663 | 663 textview.text = second |
664 // Add the two main components to the layout | 664 } |
665 imageview.id = View.generateViewId() | 665 } |
666 textview.id = View.generateViewId() | 666 |
667 rowView.addView(imageview) | 667 // Add the two main components to the layout |
668 rowView.addView(textview) | 668 imageview.id = View.generateViewId() |
669 set.clone(rowView) | 669 textview.id = View.generateViewId() |
670 set.connect(imageview.id, ConstraintSet.LEFT, textview.id, ConstraintSet.RIGHT) | 670 rowView.addView(imageview) |
671 set.applyTo(rowView) | 671 rowView.addView(textview) |
672 | 672 set.clone(rowView) |
673 // TODO: Add code to optionally add other columns | 673 set.connect(imageview.id, ConstraintSet.LEFT, textview.id, ConstraintSet.RIGHT) |
674 set.applyTo(rowView) | |
675 | |
676 // TODO: Add code to optionally add other columns | |
677 } else { | |
678 // Otherwise we just need to update the existing layout | |
679 if (model.numberOfColumns() > 1 && model.numberOfRows() > position) { | |
680 val first = model.getRowAndColumn(position, 0) | |
681 val second = model.getRowAndColumn(position, 1) | |
682 val imageview = rowView.getChildAt(0) | |
683 val textview = rowView.getChildAt(1) | |
684 | |
685 if (first is Drawable && imageview is ImageView) { | |
686 imageview.setImageDrawable(first) | |
687 } | |
688 if (second is String && textview is TextView) { | |
689 textview.text = second | |
690 } | |
691 } | |
692 } | |
674 return rowView | 693 return rowView |
675 } | 694 } |
676 } | 695 } |
677 | 696 |
678 class DWindows : AppCompatActivity() { | 697 class DWindows : AppCompatActivity() { |
2219 { | 2238 { |
2220 waitOnUiThread { | 2239 waitOnUiThread { |
2221 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter | 2240 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter |
2222 | 2241 |
2223 adapter.model.changeRowTitle(row, title) | 2242 adapter.model.changeRowTitle(row, title) |
2243 } | |
2244 } | |
2245 | |
2246 fun containerRefresh(cont: ListView) | |
2247 { | |
2248 waitOnUiThread { | |
2249 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter | |
2250 | |
2251 adapter.notifyDataSetChanged() | |
2224 } | 2252 } |
2225 } | 2253 } |
2226 | 2254 |
2227 fun containerGetColumnType(cont: ListView, column: Int): Int | 2255 fun containerGetColumnType(cont: ListView, column: Int): Int |
2228 { | 2256 { |