سلام دوستان.
من در اندروید استودیو می خوام از اکتیویتی اولی با استفاده از باتن به اکتیویتی دومی برم، کد رو نوشتم ولی موقع اجرا مشکل داره.
تازه کارم. راهنمایی کنید.
در این برنامه قرار بود بوسیله باتن BtnVorood از اکتیویتی content_main.xml به اکتیویتی activity2.xml برود!!!!!
داخل اینترنت هم چند روزه که گشتم ولی به جوابی نرسیدم.
کدهای مربوط به activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
************************************************** ****************************************
کدهای مربوط به content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ورود"
android:id="@+id/BtnVorood"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:clickable="true" />
</RelativeLayout>************************************************* *****************************************
کدهای مربوط به activity2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="اکتیویتی دوم"
android:textSize="25dp"
android:layout_weight="0.13"
android:textAlignment="center"
android:textColor="#e12727"
android:theme="@android:style/Animation" />
</LinearLayout>************************************************* *****************************************
کدهای مربوط به MainActivity.java
package com.mabdollahi.riazysara;
import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}************************************************* *****************************************
کدهای مربوط به ContentActivity.java
package com.mabdollahi.riazysara;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.widget.Button;
import android.view.View.OnClickListener;
public class ContentActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
OnClickListener listnr=new OnClickListener() {
@Override
public void onClick(View v) {
Intent i= new Intent("Activity2");
startActivity(i);
}
};
Button btn =(Button) findViewById(R.id.BtnVorood);
btn.setOnClickListener(listnr);
}
}
************************************************** ****************************************
کدهای مربوط به Activity2.java
package com.mabdollahi.riazysara;
import android.app.Activity;
import android.os.Bundle;
public class Activity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
}
}************************************************* *****************************************
کدهای مربوط به AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mabdollahi.riazysara" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="@string/app_name">
<intent-filter >
<action android:name="in.wptrafficanalyzer.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".ContentActivity"
android:label="@string/app_name">
<intent-filter >
<action android:name="in.wptrafficanalyzer.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
************************************************** ******************************************