Results 1 to 1 of 1
Thread: Java android
- 04-21-2011, 07:39 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 1
- Rep Power
- 0
Java android
Hello,
I have a problem with a small project.I need to create a a programm that has a field for a user to enter a text and a button that when pressed ,the first and last letter ef each word has to remain the same,and the other ones changer randomly.
Somethin like this:
before:The car is very fast for this road.
after:The car is vrey fast for tihs raod.
This is what i've done so far(the fisrt and the last letter of the sentence remain the same and the all the other ones change randomly)
package alex.com;
import java.util.ArrayList;
import java.util.Collections;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MixWords extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText TextEdit = (EditText) findViewById(R.id.TextEdit);
final TextView mix =(TextView) findViewById(R.id.mix);
final Button button = (Button) findViewById(R.id.proces);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action when clicking
MixMe(TextEdit.getText().toString());
}
private void MixMe(String word) {
// TODO Auto-generated method stub
ArrayList<Character> all = new ArrayList<Character>();
for (int i = 1; i < TextEdit.length()-1; i++) {//starts from the second character
all.add(word.charAt(i));
}
Collections.shuffle(all);
char a = word.charAt(0);//The first char
char b = word.charAt(TextEdit.length()-1);//The last char
String result = "";
result+=a;
for (Character character : all) {
result += character;
}
result+=b;
mix.setText(result);//shows the the mix string
}
});
}
}Last edited by amandricel; 04-21-2011 at 08:14 PM.
Similar Threads
-
Android USB
By Blackberrylerner in forum AndroidReplies: 0Last Post: 01-15-2011, 05:05 AM -
Android Java Programming: Need Help from Skilled Programmer
By AndroidAppNewbie in forum New To JavaReplies: 3Last Post: 09-18-2010, 02:41 PM -
Android
By sspkiet in forum AndroidReplies: 1Last Post: 09-03-2010, 01:14 AM -
Three new forums are created: Android, JavaFX and Java Gaming
By Java Tip in forum Java SoftwareReplies: 0Last Post: 02-16-2010, 10:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks