请选择 进入手机版 | 继续访问电脑版

星空社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 449|回复: 0

[lua教程] 【lua教程】ExpandableListView使用教程

[复制链接]

407

主题

472

帖子

1622

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1622

荣誉管理论坛元老

发表于 2021-7-1 08:36:41 来自手机 | 显示全部楼层 |阅读模式 来自:
  1. require "import"1 ^9 u9 J/ E( D, o! V0 P& i! ~
  2. import "android.app.*"! y8 ?% }; z4 Y2 v$ G+ W
  3. import "android.os.*"4 }/ Z) D0 p% r
  4. import "android.widget.*"
    / S3 X- b* Z8 {2 R8 i/ ?3 k
  5. import "android.view.*"
    0 s; {  A5 t9 j: H+ A
  6. layout={# u; B# {9 H( Y( B1 G' T+ ~
  7.   LinearLayout,  u2 n! G9 t  ^4 G, b' i  Z& T
  8.   orientation="vertical",
    0 B( b7 E* R: l# s
  9.   layout_width="fill",
    * s6 S5 |* p! `8 J# y) ~
  10.   layout_height="fill",0 H- m3 j, m' C; K
  11.   {
    0 _* b9 ^  H  |! x- I
  12.     ExpandableListView,: S0 U7 w% m* {8 B& f2 K% K* Y
  13.     id="Expandable",1 Z8 l" z% c5 \! L/ u0 t( ^1 d
  14.     layout_width="fill",
    1 c, {7 S! u, c' Y" T. _* e
  15.   },
    ' B9 Y# T: c; K5 ^1 S
  16. }* U% C  D. f! Y3 {+ K, V
  17. activity.setTheme(android.R.style.Theme_DeviceDefault_Light)--设置md主题activity.setContentView(loadlayout(layout))
    # j. `3 {' r; d- W  E
  18. activity.setContentView(loadlayout(layout))--显示# E' z- }% A6 `2 N( {

  19. 7 a: t# G( ~. D# h6 ^0 ?
  20. headLinears={+ X- Q* F$ c- X3 m8 u, t7 M9 x3 v
  21.   LinearLayout;
    ) B8 _% H. b- S/ h% o$ X
  22.   layout_width="fill";
    ' F+ e$ ~4 u2 \, t
  23.   layout_height="50dp";
    7 {/ q4 {, K1 N
  24.   orientation="vertical";
    ' }) R2 P" d7 I. H2 y# Q3 P+ ?8 y7 J
  25.   gravity="center|left";$ G( Y+ L& D3 y
  26.   background="#00ffff",
    1 B! u7 ?3 {1 r/ q4 K6 ]1 r; F
  27.   {% Q3 ]3 d" m7 t# Z0 j/ i9 K
  28.     TextView;# Z( r! }2 F- _! E& `
  29.     layout_marginLeft="40dp";* o1 ~* F  `2 ^- ^# g* o9 i
  30.     id="App_name";& @, M( [1 r  A
  31.     gravity="center";
    . X1 h, |5 q# Q5 H( |" y
  32.   };; h5 ]' B6 @& G" i
  33. };
    9 \7 \1 _3 v* M0 I3 A  m
  34. headLinears2={; E6 J1 m. N; P
  35.   LinearLayout;
    1 V6 E$ U7 }0 [
  36.   layout_width="fill";
    8 K$ V7 z/ d) _6 s7 f+ ]# m. [
  37.   layout_height="50dp";
    7 e6 Q( @8 Q8 Z8 m' h4 }
  38.   orientation="vertical";. @9 w. O0 r0 e( e
  39.   gravity="center|left";/ F9 s$ G; b' ^
  40.   background="#ff00ff",- D; Q8 n& B9 _+ o8 D+ f
  41.   {
    3 E8 @+ [  f' s7 b+ i! a  f
  42.     TextView;( ~8 @9 |4 r4 h
  43.     layout_marginLeft="45dp";% @1 [' w" I9 w9 p/ Z7 P
  44.     id="App_name";
    * ?, `9 }3 b8 f! h6 b' K' I8 s. Y
  45.     gravity="center";
    . a5 ^; t' C1 A2 ]# Q0 I
  46.   };
    - P% J1 [6 S; J3 }) ^/ L$ Y4 z- F
  47. };
      A2 E7 U) u/ T% s# p+ v
  48. ) d8 ~" v7 R. F2 S# h6 f! T1 V
  49. fg={}$ E% N  d2 X! C$ A" J
  50. fs={}
    ) h: k0 n1 X1 n8 P! r. U8 P' q
  51. ase={}
    * B% Z+ R3 [" U% f: i! U* N
  52. 8 @1 e0 F# C0 O- H0 S3 [& A
  53. ns={"Check view","Adapter view","Advanced Widget","Layout","Advanced Layout",7 y/ Q0 x7 H8 W( N
  54. }
    ' q% T* ]$ m5 Q/ U3 v1 b, m3 D

  55. 0 p+ Y' i. T2 p
  56. wds={, \1 x% L- Z; f
  57.   {"CheckBox","RadioButton","ToggleButton","Switch"},. t0 @7 \- @! K$ v+ q
  58.   {"ListView","ExpandableListView","Spinner"},
    3 Y2 n+ }0 x, s; p4 \% d4 R/ a
  59.   {"SeekBar","ProgressBar","RatingBar",. v+ y/ ^& }  S
  60.     "DatePicker","TimePicker","NumberPicker"},
    / b1 l" p! A; q( @
  61.   {"LinearLayout","AbsoluteLayout","FrameLayout"}," f2 _! N% E/ Z* L( C& K
  62.   {"RadioGroup","GridLayout",
    & ~: M; I2 X6 I5 t
  63.     "ScrollView","HorizontalScrollView"},
    3 t6 y. V1 I8 w/ V) b. l
  64. }
    % a! |# Q: I  S9 U

  65. . }# H. @9 D  G, g1 A! F' l8 t

  66. & F+ P/ ]# z8 h) H6 H5 D" y& Q  ?. n
  67. mAdapter=LuaExpandableListAdapter(activity,fg,fs,headLinears,headLinears2)  x2 R7 k+ S  a7 K0 F

  68. ' b& `+ e9 ~$ i% L; t$ y' m
  69. for k,v in ipairs(ns) do( a2 x+ r- t$ y+ ?) F* |
  70.   table.insert(fg,{App_name={Text=v}})
    ( o( x* n  C4 I8 w' z! F+ ?7 C
  71.   for ks,kv in ipairs(wds[k]) do1 z* {* `! {7 ]& N
  72.     ase[ks]={App_name={Text=wds[k][ks]}}7 y" [! `% c: F
  73.   end
    9 @6 s0 x0 j! n' G$ H- F1 V
  74.   table.insert(fs,ase)) g' `: `9 i* ?0 u5 @
  75.   ase={}2 h* c/ M+ J8 J* V; }- k7 q7 E8 u
  76. end
    ( L7 o0 V( p3 Y# y- q8 M8 m$ B
  77. & `, C* D! L3 t

  78. + H/ J% g' B8 n7 v5 ?: \
  79. mAdapter.notifyDataSetChanged(). p  T! B( e: Q% h
  80. Expandable.setAdapter(mAdapter)) a2 |1 p9 W- j

  81. 8 n7 P1 ?9 \+ Y9 e( m
  82. Expandable.onChildClick=function(l,v,g,c)5 {* p& J+ X2 }5 q
  83.   print(":ChildClick")# y- F, {/ g. N
  84. end$ a) c: j9 }- ]$ S; t0 k
  85. * z* l8 e6 V  s; i; A
  86. Expandable.onGroupClick=function(l,v,p,s)
    ) R  \! J" B1 u2 g
  87.   print(":GroupClick")
      N; b" N  @. ?/ K8 s3 v' T
  88. end
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|星空社区

GMT+8, 2022-7-1 22:42 , Processed in 0.061114 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表