我在我的项目中使用下面的代码制作动态复选框,如何获取复选框ID并为其创建命令,例如:
/*
- parameter keyLen: keyLen
- parameter ivLen: ivLen
- parameter digest: digest e.g "md5" or "sha1"
- parameter salt: salt
- parameter data: data
- parameter count: count
- returns: key and IV respectively
*/
open static func evpBytesToKey(_ keyLen:Int, ivLen:Int, digest:String, salt:[UInt8], data:Data, count:Int)-> [[UInt8]] {
let saltData = Data(bytes: UnsafePointer<UInt8>(salt), count: Int(salt.count))
var both = [[UInt8]](repeating: [UInt8](), count: 2)
var key = [UInt8](repeating: 0,count: keyLen)
var key_ix = 0
var iv = [UInt8](repeating: 0,count: ivLen)
var iv_ix = 0
var nkey = keyLen;
var niv = ivLen;
var i = 0
var addmd = 0
var md:Data = Data()
var md_buf:[UInt8]
while true {
addmd = addmd + 1
md.append(data)
md.append(saltData)
if(digest=="md5"){
md = NSData(data:md.md5()) as Data
}else if (digest == "sha1"){
md = NSData(data:md.sha1()) as Data
}
for _ in 1...(count-1){
if(digest=="md5"){
md = NSData(data:md.md5()) as Data
}else if (digest == "sha1"){
md = NSData(data:md.sha1()) as Data
}
}
md_buf = Array (UnsafeBufferPointer(start: md.bytes, count: md.count))
// md_buf = Array(UnsafeBufferPointer(start: md.bytes.bindMemory(to: UInt8.self, capacity: md.count), count: md.length))
i = 0
if (nkey > 0) {
while(true) {
if (nkey == 0){
break
}
if (i == md.count){
break
}
key[key_ix] = md_buf[i];
key_ix = key_ix + 1
nkey = nkey - 1
i = i + 1
}
}
if (niv > 0 && i != md_buf.count) {
while(true) {
if (niv == 0){
break
}
if (i == md_buf.count){
break
}
iv[iv_ix] = md_buf[i]
iv_ix = iv_ix + 1
niv = niv - 1
i = i + 1
}
}
if (nkey == 0 && niv == 0) {
break
}
}
both[0] = key
both[1] = iv
return both
}
提前谢谢。
if(checkbox1.ischecked()==true){
//do
}
答案 0 :(得分:1)
你可以这样做
cb.setId(anyPositiveInteger)
尝试此操作以获取更多详细信息How can I assign an ID to a view programmatically?
答案 1 :(得分:0)
您应该在CheckBox
ArrayList
的所有引用
List<CheckBox > allCheckBox = new ArrayList<CheckBox>();
当您创建任何CheckBox
时,您需要将其添加到List
CheckBox cb = new CheckBox(getApplicationContext());
...
allCheckBox.add(cb);
之后,您可以通过
访问CheckBox
allCheckBox.get(position).isChecked() == true
// allCheckBox.get(position) -> with return a CheckBox
// position is the index when you add checkbox to ArrayList, for example you have create 2 CheckBox dynamic
// then CheckBox1 is allCheckBox.get(0) and CheckBox2 is allCheckBox.get(1)