gpt4 book ai didi

java - 将参数从 Activity.onCreate 传递到其他方法

转载 作者:太空狗 更新时间:2023-10-29 16:20:37 25 4
gpt4 key购买 nike

我目前正在学习 Java,并且是 Android 的菜鸟。下面是我的 onCreate 方法,最后我有两个 EditText 字段,passT(纯文本)和 keyT(加密 key ) .我想将这两个作为参数传递到我的加密方法(也在下面)并检索结果并在密码 EditText 中设置值。

我想将该值设置为用户将输入的电子邮件地址(emailT,目前没有为其设置 EditText 字段)。

public class ScreenNext extends Activity {

int key = 0;
static char ch;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_next)

EditText emailT;//Import EditTexts (Key and Email)
Button send = (Button) findViewById(R.id.bSend);//Import button1 (Send)
final EditText passT = (EditText) findViewById(R.id.etTogg);//passT variable for Password Text for EditText field
final EditText keyT = (EditText) findViewById(R.id.etKey);
final EditText passT = (EditText) findViewById(R.id.etTogg);//passT variable for Password Text for EditText field

send.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
String keyText = keyT.getText().toString();
String passText = passT.getText().toString();
}

});

}//End onCreate
...
}

我的加密方法(包括其他方法,以防我的解决方案需要观察它们):

public static String message(String choice, String subKey, String message) {
int Option = Integer.parseInt(choice);//Must pareseInt
int key = Integer.parseInt(subKey);
message = message.toLowerCase();

//If the key is 26, prompt the user to change the key

if (key % 26 == 0) {

//Toast.makeText(getApplicationContext(), "You can't use a modulus of 26 as a key", Toast.LENGTH_LONG).show();

}

ScreenNext subcipher_1 = null;
String CipherTxt = subcipher_1.encrypt(message, key);
return CipherTxt;
}

// Message prompt method finished, now we create the method that has the
// encrypting algorithms

public static String encrypt(String Txt, int key) {

//local var cipherText of type string is init empty
String CipherTxt = "";//May be able to remove this'un
String cText="";
//enhanced for loop
// start at 0, go until "as long as input text"
for (int i = 0; i < Txt.length(); i++) {
//get a char from the string at index i (start at 0 work through to end of string)
// and store in local var extractedChar for type char
char extractedChar = Txt.charAt(i);
/* enhanced for loop
* start at 0, go until end of user entered cipherKeyValue
* either set to lowercase a or add one to the char
* uses the checkifz method
*/
for (int j = 0; j < key; j++) {
ScreenNext subcipher_1 = null;
if (subcipher_1.checkIfZ(extractedChar) == true) {
extractedChar = 'a';
} else {
extractedChar++;
}
CipherTxt= new StringBuilder().append(extractedChar).toString();
}
//add extracted char to builder object
//change object builder to string and assing to cipherText of type String
//create new object builder from StringBuilder class
cText = cText.concat(CipherTxt);
}
//Pass the cipherText value out of the method to whom ever called it

return cText;
}

最佳答案

在类级别声明变量

public class ScreenNext extends Activity {

int key = 0;
static char ch;
String keyText = null;
String passText = null;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ....
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
keyText = keyT.getText().toString();
passText = passT.getText().toString();
}
});
// ...
}
// ...
}

关于java - 将参数从 Activity.onCreate 传递到其他方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15935137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com