java - android eclipse button OnClick event -
i have 2 files: main_activity.xml , home.xml. made button in main_activity.xml
here code snippet:
<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>
and then, have home.xml. want button open home.xml. how can this? don't know java , new android development.
here 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>
and below 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>
and that's have. please, if reply, tell me add code such directory or between code snippets.
for managing click activity in android ,you can below
implement
onclicklistener
on youractivity.java class likepublic class mainactivity extends activity implements onclicklistener
then, declare button in .java class
button btn = (button) findviewbyid(r.id.btnplay);
then use button
btn
variable belowbtn.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { myclick(v); /* method call new intent or activity */ } });
handle click event:
public void myclick(view v) { intent intent = new intent(**this, swipe.class**); startactivity(intent);// calling activity }
you need register activity(.java) in android manifest
below
<activity android:name=".swipe" android:screenorientation="landscape" > </activity>
Comments
Post a Comment