I am unable to append a string of text from a non activity class to an EditText view.
I have tried passing a view as a parameter to the constructor of the class.
The Basic problem is that I am unable to use findViewById in a non-Activity class.
I know this is a silly question, but I have tried a lot but simply not able to get that.
My code sample is :
/*
* 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);
....
}
You can pass Context of Edittext Activity Class to Non keyGenerator Class as :
Now you can append text on keyGenerator to Edittext as:
You can pass Current Context to keyGenerator constructor as: