Results 1 to 1 of 1

Thread: Java android

  1. #1
    amandricel is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default 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

  1. Android USB
    By Blackberrylerner in forum Android
    Replies: 0
    Last Post: 01-15-2011, 05:05 AM
  2. Android Java Programming: Need Help from Skilled Programmer
    By AndroidAppNewbie in forum New To Java
    Replies: 3
    Last Post: 09-18-2010, 02:41 PM
  3. Android
    By sspkiet in forum Android
    Replies: 1
    Last Post: 09-03-2010, 01:14 AM
  4. Replies: 0
    Last Post: 02-16-2010, 10:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •