简体   繁体   English

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

[英]Android - I dont know why my intent doesnt work

So, hello guys I'm new to here and also to android but I been searching for 3 years now on StackOverflow since I first started programming on my school, at the moment I'm stuck in this problem for 2 weeks because my intent to start an activity just doesn't work, I search a lot and saw several videos and I just can't figure it out, I didn't learn Android at all at school that's why I am doing a project on it,I really enjoy programming and learning.~所以,大家好,我是这里的新手,也是 android 的新手,但是自从我第一次在学校开始编程以来,我已经在 StackOverflow 上搜索了 3 年,目前我被这个问题困了 2 周,因为我打算开始一项活动是行不通的,我搜索了很多,看了几个视频,但我就是想不通,我在学校根本没有学过 Android 这就是为什么我正在做一个项目,我真的很喜欢编程和学习。~

So my project consists of building a database to an app on Android (obviously) and a website which I'm also currently working on WordPress, my app and website are made for restaurants, cafes , similar to something like a pizza hut website but better (if I can make it I will show you guys).所以我的项目包括为 Android 上的应用程序构建一个数据库(显然)和一个我目前也在开发 WordPress 的网站,我的应用程序和网站是为餐馆、咖啡馆制作的,类似于比萨饼屋网站,但更好(如果我能做到,我会向你们展示)。 Well, I'm sorry I just thought I need to introduce my "work" and myself.好吧,对不起,我只是想我需要介绍一下我的“工作”和我自己。

Let's get to the point:让我们进入正题:

I have this image that shows you my nightmare that is probably so simple to solve.我有这张图片向您展示了我的噩梦,它可能很容易解决。

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);
}  

LAYOUT 1布局 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>  

and also the activity that I'm trying to start ( I changed only a bit of code in here)以及我试图开始的活动(我在这里只更改了一些代码)

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布局 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>

I really hope you guys help me out I because I can't find the error on the code or what should I do because again I'm really new to Android Studio I'm learning by searching I do and trying, please don't flame me and thank you.我真的希望你们帮帮我,因为我找不到代码上的错误或者我应该怎么做,因为我又是 Android Studio 的新手我正在通过搜索和尝试来学习,请不要给我发火,谢谢。

MY ANDROID MANIFEST:我的安卓清单:

  <?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>  

Make sure you AndroidManifest.xml file has the login_conta activity declared.确保您的 AndroidManifest.xml 文件声明了 login_conta 活动。 Something like this.像这样的东西。

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

Note: Use better naming for activity.注意:为活动使用更好的命名。 for example, LoginActivity and LoginContaActivity.例如,LoginActivity 和 LoginContaActivity。 (I don't know what is login_conta). (我不知道什么是 login_conta)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM