Android-我不知道为什么我的意图不起作用

时间:2019-03-15 19:40:12

标签: android

所以,大家好,我是第一次来这里,也是android的新手,但是自从我第一次在学校编程以来,我已经在StackOverflow上搜索了3年,目前我在这个问题上停留了2周,因为我开始一项活动的意图不起作用,我搜索了很多东西,看了几段视频,但我弄不清楚,在学校我根本没学过Android,这就是为什么我要在上面做一个项目,我真的很喜欢编程和学习。〜

因此,我的项目包括在Android(显然)和一个我目前也在使用WordPress的网站上为一个应用程序建立数据库,我的应用程序和网站是为餐馆,咖啡厅制作的,类似于披萨屋网站,但更好(如果可以的话,我会告诉大家)。好吧,很抱歉,我只是以为我需要介绍自己的“作品”和我自己。

让我们重点讲一下:

我有这张图片向您展示了我的噩梦,它可能很容易解决。

https://i.stack.imgur.com/dEUvH.png

protected void cl_login (View view)
{
    txt_email.requestFocus();

    if(txt_email.getText().toString().equals("") == false && txt_pw.getText().toString().equals("") == false ) {

        Toast.makeText(this, "A entrar..", Toast.LENGTH_LONG).show();

        Intent ploginconta = new Intent(this, login_conta.class);
        startActivity(ploginconta);
    }
    else {
        Toast.makeText(this, "Tem de preencher os campos para entrar na sua conta", Toast.LENGTH_LONG).show();
        txt_pw.setText("");
        txt_email.setText("");
    }
}
protected void cl_semconta (View view)
{
    Intent paginaregisto = new Intent(this, registar.class);
    startActivity(paginaregisto);
}
protected void cl_esqueceupw (View view)
{
    Intent paginaesqueceupw = new Intent(this, esqueceu_pw.class);
    startActivity(paginaesqueceupw);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    txt_pw = findViewById(R.id.txt_pw);
    txt_email = findViewById(R.id.txt_email);
    bt_login = findViewById(R.id.bt_login);
}  

布局1

  <android.support.constraint.ConstraintLayout 
   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:background="@color/colorPrimary"
tools:context=".login">

<ImageView
    android:id="@+id/img_linha3"
    android:layout_width="399dp"
    android:layout_height="8dp"
    android:layout_marginTop="32dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.466"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/rtl_login"
    app:srcCompat="@drawable/txt_view_linha" />

<TextView
    android:id="@+id/rtl_pwesquecida"
    android:layout_width="wrap_content"
    android:layout_height="20dp"
    android:layout_marginEnd="2dp"
    android:layout_marginRight="2dp"
    android:onClick="cl_esqueceupw"
    android:text="@string/pwesquecida"
    android:textColor="@android:color/holo_orange_light"
    app:fontFamily="@font/allerta"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.508"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/rtl_ntemconta"
    app:layout_constraintVertical_bias="0.095" />

<Button
    android:id="@+id/bt_login"
    android:layout_width="259dp"
    android:layout_height="35dp"
    android:layout_marginTop="48dp"
    android:background="@drawable/botao_redondo"
    android:onClick="cl_login"
    android:text="LOGIN"
    android:textColor="@color/colorPrimary"
    android:textSize="16dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txt_pw" />

<EditText
    android:id="@+id/txt_email"
    android:layout_width="259dp"
    android:layout_height="39dp"
    android:layout_marginTop="70dp"
    android:drawableLeft="@drawable/ic_action_email"
    android:ems="10"
    android:hint="EMAIL"
    android:inputType="textWebEmailAddress"
    android:textColor="@android:color/holo_orange_light"
    android:textColorHint="@android:color/holo_orange_light"
    android:textSize="12sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.504"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/rtl_login" />

<EditText
    android:id="@+id/txt_pw"
    android:layout_width="259dp"
    android:layout_height="39dp"
    android:layout_marginTop="24dp"
    android:drawableLeft="@drawable/ic_action_pw"
    android:ems="10"
    android:hint="PALAVRA-PASSE"
    android:inputType="textPassword"
    android:textColor="@android:color/holo_orange_light"
    android:textColorHint="@android:color/holo_orange_light"
    android:textSize="12sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.504"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txt_email" />

<TextView
    android:id="@+id/rtl_login"
    android:layout_width="wrap_content"
    android:layout_height="47dp"
    android:layout_marginTop="36dp"
    android:text="LOGIN"
    android:textAllCaps="false"
    android:textColor="@android:color/holo_orange_light"
    android:textSize="30sp"
    android:textStyle="bold"
    app:fontFamily="@font/biryani_extralight"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.501"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/rtl_ntemconta"
    android:layout_width="wrap_content"
    android:layout_height="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="8dp"
    android:onClick="cl_semconta"
    android:text="@string/naotemconta"
    android:textColor="@android:color/holo_orange_light"
    app:fontFamily="@font/allerta"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.503"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/bt_login"
    app:layout_constraintVertical_bias="0.023" />
    </android.support.constraint.ConstraintLayout>  

还有我要开始的活动(我在这里只更改了一点代码)

https://i.stack.imgur.com/y99Bc.png

     public class login_conta extends AppCompatActivity

    implements NavigationView.OnNavigationItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_conta);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.login_conta, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_menu) {

    } else if (id == R.id.nav_promocao) {

    } else if (id == R.id.nav_takeaway) {

    } else if (id == R.id.nav_domicilio) {

    } else if (id == R.id.nav_definicoes) {

    } else if (id == R.id.nav_facebook) {

    } else if (id == R.id.nav_avaliacao) {

    } else if (id == R.id.nav_contacte) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}  

LAYOUT 2

 <android.support.v4.widget.DrawerLayout 
 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_login_conta"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/vw_conta"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_login_conta"
    app:menu="@menu/activity_login_conta_drawer" />

    </android.support.v4.widget.DrawerLayout>

我真的希望你们能帮助我,因为我找不到代码上的错误或应该怎么做,因为我真的是Android Studio的新手,我通过搜索我尝试的方法来学习,请不要解雇我,谢谢你。

我的Android清单:

  <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aluno.pap">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".esqueceu_pw"></activity>
    <activity android:name=".pap">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".login_conta"
        android:label="@string/title_activity_login_conta"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity android:name=".login" />
    <activity android:name=".registar" />

    <meta-data
        android:name="preloaded_fonts"
        android:resource="@array/preloaded_fonts" />
</application>

 </manifest>  

1 个答案:

答案 0 :(得分:0)

确保您的AndroidManifest.xml文件具有声明的login_conta活动。 像这样的东西。

<activity android:name=".login_conta" />

注意:为活动使用更好的命名。例如,LoginActivity和LoginContaActivity。 (我不知道什么是login_conta)。