我無法文本字符串從非活性類追加到一個EditText視圖追加一個EditText。從非活性
我試圖傳遞一個視圖作爲參數的類的構造函數。
基本問題是我無法在非活動類中使用findViewById。
我知道這是一個愚蠢的問題,但我嘗試了很多,但根本無法得到。
我的代碼示例是:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.printtesting;
import android.app.Activity;
import android.widget.EditText;
import java.math.BigInteger;
import java.util.Random;
import java.util.Vector;
//import javax.swing.JOptionPane;
/**
*
* @author HP
*/
public class keyGenerator {
/**
* @param args the command line arguments
*/
static Vector check = new Vector();
static protected BigInteger p= new BigInteger("161");
static protected BigInteger q= new BigInteger("47");
static protected Random s = new Random();
static protected BigInteger n = new BigInteger("1");
static protected BigInteger trails;
static protected BigInteger lambda ;
static protected BigInteger nsq = new BigInteger("1");
static protected BigInteger g = new BigInteger("1");
static protected BigInteger temp = new BigInteger("1");
static protected int maxbit;
private static BigInteger two = new BigInteger("2");
public keyGenerator() {
// p = new BigInteger(7,1,s);
System.out.println(p.toString());
/* while(!isPrime(p) && ((p.compareTo(two)==1) || (p.compareTo(two))==0))
{
p = new BigInteger(7,1,s);
System.out.println(p.toString());
}*/
System.out.println("P is " + p);
// q = new BigInteger(7,1,s);
/* while(!isPrime(q) && ((q.compareTo(two)==1) || (q.compareTo(two))==0))
{
q = new BigInteger(7,1,s);
}*/
System.out.println("Q is " + q);
// TODO code application logic here
// BigInteger oth = new BigInteger("132312");
generateKey();
}
protected void generateKey()
{
EditText et = (EditText) Activity.findViewByID(R.string.te);
// N=pq
n=n.multiply(p);
n=n.multiply(q);
....
}
爲什麼不將EditText **內容**傳遞給keyGenerator類?將View發送到非活動類時必須小心,因爲如果非活動類超出活動的使用期限,可能會導致泄漏 – nicopico