写代码的人

按钮事件,模式窗体

layout:

<Button

android:id=”@+id/firstButton”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

/>

activity:

public class FirstActivity extends Activity {

private Button firstButton;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

firstButton = (Button)findViewById(R.id.firstButton);

firstButton.setText(R.string.firstButton);

firstButton.setOnClickListener(new FirstButtonListener());

}

class FirstButtonListener implements OnClickListener{

@Override

public void onClick(View v) {

Intent intent = new Intent();

intent.setClass(FirstActivity.this, SecondActivity.class);

startActivity(intent);

}

}

}

AndroidManifest.xml文件:

<application android:icon=”@drawable/icon” android:label=”@string/app_name”>

<activity android:name=”.FirstActivity”

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=”.SecondActivity”

android:label=”@string/dialogActivityStr”

android:theme=”@android:style/Theme.Dialog”

/>

</application>

效果:

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: