Android的日食按钮OnClick事件 [英] android eclipse button OnClick event
问题描述
我有2个文件:main_activity.xml和home.xml。我在main_activity.xml做了一个按钮
I have 2 files: main_activity.xml and home.xml. I made a button in main_activity.xml
下面是code片断:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/splash_background"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="43dp"
android:onClick="home"
android:text="Home" />
</RelativeLayout>
然后,我有我的home.xml。我想按钮,打开home.xml。我怎样才能做到这一点? 我不知道任何Java和我是新android开发。
And then, I have my home.xml. I want the button to open up home.xml. How can i do this? I don't know any java and I am new to android development.
下面是我下面的home.xml:
Here is my home.xml below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/app_bg"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
和下面是我的AndroidManifest.xml:
And below is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.idozer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.idozer.SplashActivity"
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="com.example.idozer.MainActivity"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
这就是我的一切。请,如果你回复,告诉我在哪里添加code如目录或code片段之间。
And that's all I have. Please, if you reply, tell me where to add the code such as the directory or between code snippets.
推荐答案
有关管理点击行为在Android中,你可以做如下
For managing click activity in android ,you can do as below
-
实施
OnClickListener
在 YourActivity.java 喜欢
公共类MainActivity扩展活动实现OnClickListener
然后,声明你的按钮的.java类如
Then, declare your button in .java class like
按钮BTN =(按钮)findViewById(R.id.btnPlay);
然后使用按钮 BTN
变量如下
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myClick(v); /* my method to call new intent or activity */
}
});
处理Click事件:
Handle the click event:
public void myClick(View v) {
Intent intent = new Intent(**this, Swipe.class**);
startActivity(intent);// for calling the activity
}
您还需要在 Android清单注册您的活动(的.java)
如下
<activity
android:name=".Swipe"
android:screenOrientation="landscape" >
</activity>
这篇关于Android的日食按钮OnClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!