开发者

Linking two activity in android

I'm coding a simple android app where you write in a box your name then click ok and a new page will show your name... The problem is that when you click ok nothing happens.

Here the main activity

public class Click extends Activity implements OnClickListener{

        @Override
        public void onClick(View v) {
                // TODO Auto-generated method stub
                String TypedText = (String)MyText.getText().toString();
                Intent MyInt = new Intent(this, HelloWorld.class);
                MyInt.putExtra("user", TypedText);
                this.startActivity(MyInt);     
                Bundle Retrive = this.getIntent().getExtras();
                Retrive.getString("user");
                setContentView(R.id.Text);
                TextView TextV = (TextView)findViewById(R.id.Text);
                TextV.setText("user");                   

        }
        android.widget.EditText MyText;

        public void OnCreate (Bundle savedInstanceState){
                super.onCreate(savedInstanceState);
                this.setContentView(R.layout.name_getter);
                MyText = (EditText)this.findViewById(R.id.editText1);
                thi开发者_运维技巧s.findViewById(R.id.button1);
                android.widget.Button RefBut = (Button)this.findViewById(R.id.button1);
                RefBut.setOnClickListener(this);

                }

And here the manifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="edu.calpoly.android.lab1Sada"
     android:versionCode="1"
     android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Click"
                 android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="HelloWorld" ></activity>

    </application>
</manifest>

Starting the android emulator will launch the first activity click but then the app doesn't show the new view...


I dont know what you are doing but you can send/retrieve data from/to activity to another activity like this way:

For that you need to understand the concept of Intent.

From First activity:

Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("name", "paresh");
i.putExtra("technology", "android");
startActivity(i);

From Second activity:

Bundle extras = getIntent().getExtras();
if (extras == null) {
    return;
}
String strName = extras.getString("name");
String strTechnology = extras.getString("technology");

Still for your reference, here is the article to know more about the same: Android Intents


You must pass the text from activity 1 and receive it as bundle in activity 2.

Go through the helloworld program as your first tutorial for android.

Just extending Activity will work. You do not need to mention the entire package of the superclass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜