小编rez*_*zam的帖子

通过变量从Strings.xml获取字符串

我想从strings.xml中获取一个字符串.我知道怎么做 但我的问题是别的:我有一个每次更改的字符串变量,每次更改时,我想查看strings.xml并检查字符串变量是否存在于Strings.xml中,然后获取文本.

例如:

String title="sample title" \\ which changes
String city= "sample city"
String s = getResources().getString(R.string.title);
Run Code Online (Sandbox Code Playgroud)

在第三行:title是一个String,并且在Strings.xml中没有任何名为String的"title"我该怎么做?请帮我

android

7
推荐指数
1
解决办法
1万
查看次数

如何使用Elixir中的AES CBC 128进行加密和解密

我在Rails中有一个应用程序,它有以下方法来加密和解密文本并与Java客户端通信.

def encrypt(string, key)
    cipher = OpenSSL::Cipher::AES.new(128, :CBC)
    cipher.encrypt
    cipher.padding = 1
    cipher.key = hex_to_bin(Digest::SHA1.hexdigest(key)[0..32])
    cipher_text = cipher.update(string)
    cipher_text << cipher.final
    return bin_to_hex(cipher_text).upcase
end

def decrypt(encrypted, key)
    encrypted = hex_to_bin(encrypted.downcase)
    cipher = OpenSSL::Cipher::AES.new(128, :CBC)
    cipher.decrypt
    cipher.padding = 1
    cipher.key = hex_to_bin(Digest::SHA1.hexdigest(key)[0..32])
    d = cipher.update(encrypted)
    d << cipher.final
rescue Exception => exc
end

def hex_to_bin(str)
    [str].pack "H*"
end

def bin_to_hex(str)
    str.unpack('C*').map{ |b| "%02X" % b }.join('')
end
Run Code Online (Sandbox Code Playgroud)

我需要在Elixir中为凤凰框架做同样的事情.由于我是Elixir的新手,我找不到办法.我发现Elixir使用了Erlang的:crypto模块.在文档中没有AES CBC加密方法.

ruby erlang elixir phoenix-framework

5
推荐指数
1
解决办法
4001
查看次数

从编程添加按钮获取OnClick()?

我在布局中添加了一些按钮:

LinearLayout row = (LinearLayout)findViewById(R.id.KeysList);
    keys=db.getKeys(console);

    my_button=new Button[keys.size()];
    for (bt=0;bt<keys.size();bt++){
           my_button[bt]=new Button(this);
           my_button[bt].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT));
           my_button[bt].setText(keys.get(bt));
           my_button[bt].setId(bt);
           row.addView(my_button[bt]);
           my_button[bt].setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (my_button[bt].getId() == ((Button) v).getId()){
                      Toast.makeText(getBaseContext(), keys.get(bt), 0).show();
                  }
              }
           });
        }
Run Code Online (Sandbox Code Playgroud)


我想知道单击了哪个按钮以及如何获取单击按钮的文本?
我认为在这里使用bt似乎不起作用!

android onclick button buttonclick onclicklistener

1
推荐指数
1
解决办法
7895
查看次数