Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asking name and storing it?

I have huge problem. Have searching answer from many places but I do not find answer to question.

I have 2 classes in java. One is "main" and other is "menu"

On main, there is editText where person can type name and button ok.

When you press ok, I want to specific thing happen. That is where I need help. I am newcomer in Android.

I want that in other class, where will be main application and stuff, the entered name would be displayed. For example "Welcome " + name

I have tried many ways but I do not get it to work. So I want it to get one of 2 possible ways.

  1. Set string in class 1 and then when it goes class 2, then it imports the string from class 1 to class 2 so I can use it.
  2. I set string in class 2 and then in Class 1 I change the string in class 2, so the main 'data' string is actually in class 2, where I will continue using it if needed!

I have searched it from many places, used google and this database, but haven't found answer.

My codes are really nothing much, so no point pasting them here :).

Thanks for the help!


edit:// Ok, here are some codes then :)

package viimane.voimalus.incule;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ViimaneVoimalusActivity extends Activity {

    public static final String PREFS_NAME = "MyPrefsFile";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button oknupp = (Button) findViewById(R.id.nimiOK);
        oknupp.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub



                startActivity(new Intent("viimane.voimalus.in" +cule.REALMENU"));
            }
        });
    }
}

package viimane.voimalus.incule;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class RealMenu extends Activity {

    EditText nimesisestus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.peamenu);
    }

}
like image 361
Elven Avatar asked Dec 14 '25 01:12

Elven


1 Answers

You didn't show any code at all, so the answer won't be too detailed.

  1. You can pass a String in the intent used to start the second activity, using putExtra method. In the second activity you may get the string by calling getStringExtra(). If you don't know much about starting activity and intents, there are many resources on the web, for example - this one.
  2. To receive text input use EditText and to put text on the screen (that the user can't cange) use TextView.

Those are starting points. Next time I hope the question will be more focused.

like image 127
MByD Avatar answered Dec 15 '25 14:12

MByD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!