如何从混杂的EditText一个字并应用混乱的字变成一个TextView [英] How to jumble a word from EditText and apply the jumbled word into a TextView
本文介绍了如何从混杂的EditText一个字并应用混乱的字变成一个TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何混杂进入的EditText一个字。
I need to know how to jumble a word entered into EditText.
的杂乱字将显示在相同的接口的另一TextView的。
The jumbled word will show in another TextView in the same interface.
我也试过这样做,但我得到一个强制关闭错误。这是我在按钮中尝试:
I have tried to do this but I get a force close error. This is what I have tried within the button:
wordE = (EditText)findViewById(R.id.entry);
jumble = (TextView) findViewById(R.id.jumble);
Button link5Btn = (Button)findViewById( R.id.selected );
link5Btn.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
jumbleMe(al);
}
哪个调用方法:
private void jumbleMe( String word ){
al = wordE.getText().toString();
ArrayList<Character> al = new ArrayList<Character>();
for (int i = 0; i < wordE.length(); i++) {
al.add(word.charAt(i));
}
Collections.shuffle(al);
jumble.setText( al.toString() );
}
我想AP preciate有这方面的帮助。谢谢
I would appreciate any help on this. Thanks
推荐答案
您犯了一些错误。
试着改变code为:
link5Btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
jumbleMe(wordE.getText().toString());
}
});
和
private void jumbleMe(String word) {
ArrayList<Character> al = new ArrayList<Character>();
for (int i = 0; i < wordE.length(); i++) {
al.add(word.charAt(i));
}
Collections.shuffle(al);
String result = "";
for (Character character : al) {
result += character;
}
jumble.setText(result);
}
这篇关于如何从混杂的EditText一个字并应用混乱的字变成一个TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文