I have a logic error in a simple android app;
I have 3 Buttons (Permute, Clear and GC), 1 EditText and a TextView. When the Permute button is clicked it sends the text in the EditText box to a method from another class and sets the returned value to the TextView. The returned value is just gibberish text.

When I click the Clear, it clears the current contents of the EditText box and the TextView; (by setting the contents to a null string “”).

However when I click Permute with new values in the textBox, the old (cleared) text returns along with the newer text below

Here’s the code:
package com.mobinga.string;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.mob.string.Perm;
public class MoPermActivity extends Activity implements View.OnClickListener {
Button btn;
Button btn2;
Button btn3;
EditText et;
TextView tv;
Vibrator vi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.Permute);
btn2 = (Button) findViewById(R.id.Clear);
btn3 = (Button) findViewById(R.id.GC);
btn.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
et = (EditText) findViewById(R.id.Text);
tv = (TextView) findViewById(R.id.textView1);
}
public void onClick(View view){
switch(view.getId()){
case R.id.Permute:
vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vi.vibrate(50);
tv.setText(Perm.perm(et.getText().toString()));
break;
case R.id.Clear:
vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
et.setText("");
tv.setText("");
vi.vibrate(50);
break;
case R.id.GC:
vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
GC();
vi.vibrate(50);
}
}
public static void GC(){
Log.d("Permute","Calling GC");
System.gc();
}
}
How do I properly and completely clear the contents of TextView, and stop it from returning? Simply put : My problem is that the supposedly cleared contents of the TextView return back even after clearing.
Edit if necessary here’s the Perm Class
package com.mob.string;
public class Perm {
static String v = "";
static void permute(int level, String permuted, boolean used[], String original) {
int length = original.length();
if (level == length) {
v +=permuted+"\n";
} else {
for (int i = 0; i < length; i++) {
if (!used[i]) {
used[i] = true;
permute(level + 1, permuted + original.charAt(i), used, original);
used[i] = false;
}
}
}
}
public String perm(String s){
boolean used[] = {false, false, false, false, false,false,false};
permute(0, "", used, s);
return v;
}
}
v is never reset.
However I don’t see why v even exists to be honest. I would of passed it through the recursive calls.