注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[注解]列表类控件例程CheckListDemo2  

2014-08-24 11:31:01|  分类: B.官网类库 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
[注解]列表类控件例程CheckListDemo2 - 沉默蜂 - 沉默蜂B4A安卓编程实战资料
 例程效果图


此博客日志只是MAIN模块的代码,例程中涉及到的ClsCheckList类模块代码见 《 注解类模块ClsCheckList代码 》
更多信息参考博客日志:《 可用于设置界面的检查框列表类CheckList   和 《 自定义列表视图_CustomListView 》 


#Region 代码说明

'版本:2014-08-10
'注解:沉默蜂(QQ793136625)
'博客:http://silentbees.blog.163.com

' 来源 [Class] CheckList
'http://www.basic4ppc.com/android/forum/threads/class-checklist.18853/

'这个例程我在2014年4月的时候就已接触到了,但要想较深入地分析清楚一个控件是一件较消耗时间的事,
'所以这事一直停下来了,这次手头上的一个B4A项目需要增加一个设置属性的界面,于是想到了这个CheckList控件

#End Region

#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: CheckList demo
#VersionCode: 1
#VersionName: 
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim svList As ScrollView
Dim lst As ClsCheckList
Dim btnOrder As Button
Dim btnChangeStyle As Button
Dim btnSortQty As Button
Dim WhiteBackground As BitmapDrawable
Dim GreenBackground As BitmapDrawable
End Sub

Sub Activity_Create(FirstTime As Boolean)

' Colored background
Activity.LoadLayout("main2.bal")
'开始:给屏幕绘制渐变背景色 -------------------------------------------------------------------------
Dim gd As GradientDrawable
Dim C(2) As Int
C(0) = Colors.Blue
C(1) = Colors.Black
gd.Initialize("TL_BR", C)
Activity.Background = gd
'结束:给屏幕绘制渐变背景色 -------------------------------------------------------------------------


' List generation
Dim Hght As Int
Hght = 40dip
lst.Initialize(Me, svList, "", "lst_Click", "", 1dip)
' lst.CheckedColor = Colors.RGB(255, 0, 0)'检查框点击时的颜色
' lst.ExtensionColor = Colors.ARGB(128, 255, 255, 255)'扩展区展开时的颜色
lst.CheckedColor = Colors.red'检查框点击时的颜色
lst.ExtensionColor = Colors.green'扩展区展开时的颜色
' lst.AddHeader("Tables (made in France)")
lst.AddHeader("何为幸福")'增加一个标题
For i= 0 To 100
'增加一个自定义的条目
lst.AddCustomItem(i, CreateItem(Hght, i), Hght)
' If i = 10 Then lst.AddHeader("Chairs (made in China)")
' If i = 40 Then lst.AddHeader("Chairs (made in USA)")
If i = 10 Then lst.AddHeader("少欲知足")
If i = 20 Then lst.AddHeader("知足长乐")
Next
'自动调整ScrollView面板高度
lst.ResizePanel
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub


'创建自定义条目
Sub CreateItem(h, i As Int) As Panel
Dim pnl As Panel, lbl As Label, chk As CheckBox, edt As EditText
pnl.Initialize("")

chk.Initialize("ChkBx") 'View #0
pnl.AddView(chk, 0, 0, 40dip, h)

lbl.Initialize("") 'View #1
lbl.Text = "少欲 #" & i
lbl.TextColor = Colors.Blue
lbl.TextSize = 18
lbl.Gravity = Gravity.CENTER_VERTICAL
pnl.AddView(lbl, 45dip, 0, lst.getWidth - 130dip, h)
edt.Initialize("") 'View #2
edt.Visible = False
edt.Hint = "Qty"
edt.InputType = edt.INPUT_TYPE_NUMBERS
pnl.AddView(edt, lst.getWidth - 81dip, 1dip, 80dip, h)

Return pnl
End Sub


'检查框点击时触发此事件
Sub ChkBx_CheckedChange(Checked As Boolean)
Dim pnl As Panel
pnl = lst.FindPanelContaining(Sender)
If Checked Then
ExpandItem(pnl, pnl.Tag)
Else
If lst.HasExtraContent AND lst.ExtendedItemID = pnl.Tag Then
lst.CollapseItem
Else
lst.Repaint(pnl)
End If
End If
Dim edt As EditText
edt = pnl.GetView(2)
edt.Visible = Checked
If Checked Then
If edt.Text = "" Then edt.Text = 1
Else
edt.Text = ""
End If
End Sub

Sub ExpandItem(pnl As Panel, ID As Object)
' We expand the clicked item
Dim pnlDetails As Panel, lbl As Label
pnlDetails.Initialize("")
lbl.Initialize("")
lbl.TextColor = Colors.White
lbl.TextSize = 18
If ID < 10 Then
lbl.Text = "Dimensions: 100x80x78" & CRLF & "Available in stock"
Else
lbl.Text = "Dimensions: 50x60x23" & CRLF & "Available in stock"
End If
pnlDetails.AddView(lbl, 5dip, 0, lst.getWidth, 55dip)
lst.ExtendItem(ID, pnlDetails, 55dip)
End Sub

Sub lst_Click(pnl As Panel, ID As Object)
Dim lbl As Label
lbl = pnl.GetView(1)
Activity.Title = "You clicked on " & lbl.Text

If lst.HasExtraContent AND lst.ExtendedItemID = ID Then
' We collapse the clicked item if this item is the extended item
lst.CollapseItem
Else
' We expand the clicked item
ExpandItem(pnl, ID)
End If
End Sub

Sub btnOrder_Click
' The selected products ID are in lst.CheckedList
Msgbox("You selected " & lst.CheckedList.Size & " products.", "Order")
End Sub

Sub Background_Set(pnlItem As Panel, State As Int)
Select State
Case 0, 1 ' Default, Extended
pnlItem.Background = WhiteBackground
Case 2, 3 ' Checked, Extended+Checked
pnlItem.Background = GreenBackground
Case 4 ' Pressed
pnlItem.Color = Colors.Green
End Select
End Sub

Sub btnChangeStyle_Click
WhiteBackground.Initialize(LoadBitmap(File.DirAssets, "white_bg.png"))
GreenBackground.Initialize(LoadBitmap(File.DirAssets, "green_bg.png"))
lst.SetOnPaintListener("Background_Set")
lst.DividerColor = Colors.Black
Dim pnl As Panel, lbl As Label, chk As CheckBox, edt As EditText
For i = 0 To lst.NumberOfItems - 1
pnl = svList.Panel.GetView(i)
If pnl.Tag = Null Then Continue 'It's a header
chk = pnl.GetView(0)
lbl = pnl.GetView(1)
edt = pnl.GetView(2)
lbl.TextColor = Colors.Black
lbl.Left = 90dip
chk.Left = 100%x - 50dip
edt.Left = 0
lst.Repaint(pnl)
' Don't add/remove views and don't change panel top or height when you change the layout of an item.
' To create a very different layout, use lst.ReplaceItem instead.
Next
btnChangeStyle.Visible = False
End Sub

Sub btnSortQty_Click
' We sort by quantity the three sections (items between headers)
' EditText = View #2
lst.SortItems(lst.CreateIntegerList(2, 1, 11), 1, 11, False)
lst.SortItems(lst.CreateIntegerList(2, 13, 42), 13, 42, False)
lst.SortItems(lst.CreateIntegerList(2, 44, lst.NumberOfItems - 1), 44, lst.NumberOfItems - 1, False)
End Sub

  评论这张
 
阅读(162)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017