У меня есть два макета (xml-файлы), и я хочу переключаться с одной страницы на другую, два xml-файла - это main.xml и register.xml, если я нажму кнопку входа в main.xml, страница должна развернуться и отобразиться register.xml, а также в register.xml, если я нажму кнопку «Отправить», он должен перейти к main.xml. Я много пробовал с этим действием и не могу сделать это, так как я новичок в android
пожалуйста, кто-нибудь поделится кодом для меня,
вот мои два xml кода
main.xml
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:background="@drawable/loginapp">
<RelativeLayout android:id="@+id/relativeLayout1" android:gravity="center" android:layout_marginTop="25dip" android:layout_height="177dip" android:background="@drawable/login_form_bg_green" android:layout_width="296dip">
<EditText android:layout_marginRight="0dip" android:id="@+id/userNameBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginLeft="85dip" android:inputType="text" android:layout_height="wrap_content"></EditText>
<EditText android:layout_marginRight="0dip" android:id="@+id/passwordBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginTop="45dip" android:layout_marginLeft="85dip" android:inputType="text|textVisiblePassword" android:layout_height="wrap_content"></EditText>
</RelativeLayout>
<LinearLayout android:id="@+id/ll_three" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/ll_two" android:gravity="center">
<Button
android:text="Sign In"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginRight="15dip"
android:layout_height="wrap_content"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:id="@+id/Button02"
android:text="New user"/>
register.xml is
<TableRow>
<TextView android:id="@+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" REGISTER:"/>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name:"/>
<EditText android:layout_marginRight="0dip"
android:id="@+id/userNameBox" android:background="@android:drawable/editbox_background"
android:maxLines="1" android:layout_marginLeft="15dip" android:layout_weight="1"
android:inputType="text" android:layout_height="35px" android:layout_width="0dip"></EditText>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name:"/>
<EditText android:layout_marginRight="0dip"
android:id="@+id/userNameBox" android:layout_width="200px" android:layout_weight="1"
android:background="@android:drawable/editbox_background" android:maxLines="1"
android:layout_marginLeft="15dip" android:inputType="text"
android:layout_height="35px"></EditText>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email:"/>
<EditText
android:id="@+id/userNameBox" android:layout_width="200px"
android:background="@android:drawable/editbox_background" android:layout_weight="1"
android:maxLines="1" android:layout_marginLeft="15dip" android:layout_marginRight="0dip"
android:inputType="text" android:layout_height="35px">
</EditText>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile No:"/>
<EditText android:layout_marginRight="0dip"
android:id="@+id/userNameBox" android:layout_width="200px" android:layout_weight="1"
android:background="@android:drawable/editbox_background"
android:maxLines="1" android:layout_marginLeft="15dip"
android:inputType="text" android:layout_height="35px">
</EditText>
</TableRow>
ЗДЕСЬ МОИ ФАЙЛЫ JAVA
login.java
package com.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Login extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button newuser = (Button) findViewById(R.id.Button02);
newuser.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Register.class);
startActivityForResult(myIntent, 0);
}
});
}
}
Register.java
package com.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Register extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
Button register = (Button) findViewById(R.id.Button03);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
}}
при отладке проекта я обнаружил ошибки DDMS
Android [Приложение для Android]
DalvikVM [локальный: 8759]
Поток [<1> main] (Приостановлено (исключение RuntimeException))
Строка ActivityThread.performLaunchActivity (ActivityThread $ ActivityRecord, Intent): 2585
Строка ActivityThread.handleLaunchActivity (ActivityThread $ ActivityRecord, Intent): 2679
ActivityThread.access $ 2300 (ActivityThread, ActivityThread $ ActivityRecord, Intent) строка: 125
Строка ActivityThread $ H.handleMessage (Message): 2033
ActivityThread $ H (обработчик) .dispatchMessage (сообщение) строка: 99
Looper.loop () строка: 123
Строка ActivityThread.main (String []): 4627
Строка Method.invokeNative (Object, Object [], Class, Class [], Class, int, boolean): недоступно [собственный метод]
Строка Method.invoke (Object, Object ...): 521
ZygoteInit $ MethodAndArgsCaller.run () строка: 868
ZygoteInit.main (String []) строка: 626
NativeStart.main (String []) строка: недоступно [собственный метод]
Нить [<6> Binder Thread # 2] (работает)
Нить [<5> Binder Thread # 1] (работает
LOGCAT показывает это
04-24 16: 24: 18.965: ОШИБКА / HierarchicalStateMachine (58): TetherMaster - необработанное сообщение: msg.what = 3
04-24 16: 24: 20.415: WARN / ActivityManager (58): Тайм-аут простоя активности для HistoryRecord {44f2b188 com.android.launcher / com.android.launcher2.Launcher}
04-24 16: 24: 22.965: WARN / WindowManager (58): истекло время ожидания зависания приложения.
04-24 16: 24: 22.965: WARN / WindowManager (58): Принудительная очистка блокировки: AppWindowToken {450698d0 token = HistoryRecord {44f2b188 com.android.launcher / com.android.launcher2.Launcher}}
04-24 16: 24: 23.645: WARN / GoogleLoginService (180): на устройстве нет аккаунтов: отправка намерений {act = com.google.android.gsf.LOGIN_ACCOUNTS_MISSING}
04-24 16: 24: 31.296: WARN / PackageManager (58): путь к коду для pkg: com.android.cardioworld меняется с /data/app/com.android.cardioworld-1.apk на / data / app / com. android.cardioworld-2.apk
04-24 16: 24: 31.296: WARN / PackageManager (58): путь ресурса для pkg: com.android.cardioworld меняется с /data/app/com.android.cardioworld-1.apk на / data / app / com. android.cardioworld-2.apk
04-24 16: 24: 34.216: WARN / RecognitionManagerService (58): доступные службы распознавания голоса не найдены
04-24 16: 24: 36.214: WARN / SystemClock (123): невозможно установить rtc в 1303642476: неверный аргумент
04-24 16: 24: 41.174: WARN / ActivityThread (318): приложение com.android.cardioworld ожидает отладчик на порту 8100 ...
04-24 16: 24: 50.686: WARN / ActivityManager (58): Тайм-аут запуска истек, отказавшись от блокировки пробуждения!
04-24 16: 24: 51.170: WARN / ActivityManager (58): Тайм-аут простоя активности для HistoryRecord {450caa98 com.android.cardioworld / .login}