• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Making my first Android app (and got stuck) :)

Hello everybody :)

I just started developing apps for Android in Eclipse and I came upon an interesting challenge. I started working on an application that:
When launched, shows an input field to enter a sentence and a standard button
When the button is pressed, the application shows the same sentence (pretty easy so far right? :D ) with the following change:

The first and last letter of each word is kept the same while all other letters (if any) are randomly mixed.

And here is where I got stuck as I have no idea where to begin doing it.
It's basically the "Making an Android App for NOOBS!" thread but with a twist :)
Thanks and happy coding :cool:
 
So you are able to get the application to start up with the text field and the button that display information? That is essentially it. The only other thing I think you would have to do is set an onClickListener for the button. The listener should grab the text from the EditText. Next you will look at the length of the String. You then take the first character using text.charAt(0) and add it to a string that we'll call "random". for length - 2 times you will generate a random character

Code:
char c = (char) ('a' + ((int) (Math.random() * 26)))

You now add c to "random". Now you add text.charAt(text.length() -1) to "random". You now have your random String that is the same length with the first and last letter the same as the string entered in the EditText
 
So you are able to get the application to start up with the text field and the button that display information? That is essentially it. The only other thing I think you would have to do is set an onClickListener for the button. The listener should grab the text from the EditText. Next you will look at the length of the String. You then take the first character using text.charAt(0) and add it to a string that we'll call "random". for length - 2 times you will generate a random character

Code:
char c = (char) ('a' + ((int) (Math.random() * 26)))
You now add c to "random". Now you add text.charAt(text.length() -1) to "random". You now have your random String that is the same length with the first and last letter the same as the string entered in the EditText


Thanks for the reply! Very interesting idea;)
I've got the on click listener, but now I'm stuck with the strings:mad::

Code:
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.util.*;



public class main extends Activity {
        /** Called when the activity is first created. */
    
    TextView TextOut;
    EditText getinput;
    
    
    
    
    @Override
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
     
        TextOut = (TextView) findViewById(R.id.textView);
        getinput = (EditText) findViewById (R.id.EditText);
        Button Show = (Button) findViewById (R.id.button1);
        Show.setOnClickListener (new View.OnClickListener() {
                        
            public void onClick(View v) {
                // TODO Auto-generated method stub
                TextOut.setText(getinput.getText());
                
                
            }
        });
        
    }
      
            
    
        
        
    }     
       
}
 
you'd probably need to do something like this
Code:
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.util.*;

public class main extends Activity {
    /** Called when the activity is first created. */

    TextView TextOut;
    EditText getinput;
    String sentance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextOut = (TextView) findViewById(R.id.textView);
        getinput = (EditText) findViewById(R.id.EditText);
        Button Show = (Button) findViewById(R.id.button1);
        Show.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                TextOut.setText(getinput.getText());
                sentance = getinput.getText().toString();
                sentance = modify(sentance);
                TextOut.setText(sentance);

            }
        });

    }

    public String modify(String x) {
        // do your algorithm here
        return x;
    }

}
you just need to implement your algorithm inside the modify() function .. without that it's gonna print whatever you type without modification

I haven't tested the code above .. but it should work
 
Back
Top Bottom