android onClick不起作用

时间:2016-05-02 16:55:02

标签: android android-layout

代码在其他布局中运行良好,但在其他布局中没有..

布局XML:

<Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="register"
        android:id="@+id/welcome_register"
        android:background="@android:color/holo_green_dark"
        android:textColor="#ffffff"
        android:textSize="25sp"
        android:onClick="register_Click" />

的活动:

package il.co.smartchip.hobby;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        getSupportActionBar().hide();
    }

    public void start_login(View view) {
        //TODO log in
    }

    public void register_Click(View view) {
        Intent intent = new Intent(this, RegisterActivity.class);
        startActivity(intent);
    }

我尝试了几件事没有成功。你知道它为什么不起作用吗?

2 个答案:

答案 0 :(得分:0)

  

在xml上删除onclick

default_keychain
  

按照那样启动你的按钮

[Mon May 02 16:58:23.316772 2016] [ssl:info] [pid 16850] [client IP:29158] AH01964: Connection to child 1 established (server server:443)
[Mon May 02 16:58:23.352418 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(485): AH00831: socache_shmcb_store (0x81 -> subcache 1)
[Mon May 02 16:58:23.352488 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(810): AH00847: insert happened at idx=0, data=(0:32)
[Mon May 02 16:58:23.352500 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(815): AH00848: finished insert, subcache: idx_pos/idx_used=0/1, data_pos/data_used=0/180
[Mon May 02 16:58:23.352542 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(506): AH00834: leaving socache_shmcb_store successfully
[Mon May 02 16:58:23.352600 2016] [ssl:debug] [pid 16850] ssl_engine_kernel.c(1812): [client IP:29158] AH02041: Protocol: TLSv1, Cipher: RC4-SHA (128/128 bits)
[Mon May 02 16:58:23.370771 2016] [ssl:debug] [pid 16850] ssl_engine_kernel.c(224): [client IP:29158] AH02034: Initial (No.1) HTTPS request received for child 1 (server server:443)
[Mon May 02 16:58:23.371004 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of Require all granted: granted
[Mon May 02 16:58:23.371015 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of <RequireAny>: granted
[Mon May 02 16:58:23.371202 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of Require all granted: granted
[Mon May 02 16:58:23.371211 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of <RequireAny>: granted
[Mon May 02 16:58:23.371650 2016] [:info] [pid 16839] [remote IP] mod_wsgi (pid=16839, process='project', application=''): Loading WSGI script '/usr/local/env/project/apache/project.wsgi'.
[Mon May 02 16:58:23.849532 2016] [:error] [pid 16839] [remote IP] mod_wsgi (pid=16839): Target WSGI script '/usr/local/env/project/apache/project.wsgi' cannot be loaded as Python module.
[Mon May 02 16:58:23.849596 2016] [:error] [pid 16839] [remote IP] mod_wsgi (pid=16839): Exception occurred processing WSGI script '/usr/local/env/project/apache/project.wsgi'.
[Mon May 02 16:58:23.849636 2016] [:error] [pid 16839] [remote IP] Traceback (most recent call last):
[Mon May 02 16:58:23.849671 2016] [:error] [pid 16839] [remote IP]   File "/usr/local/env/project/apache/project.wsgi", line 13, in <module>
[Mon May 02 16:58:23.849742 2016] [:error] [pid 16839] [remote IP]     application = get_wsgi_application()
[Mon May 02 16:58:23.849775 2016] [:error] [pid 16839] [remote IP]   File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon May 02 16:58:23.849832 2016] [:error] [pid 16839] [remote IP]     django.setup()
[Mon May 02 16:58:23.849850 2016] [:error] [pid 16839] [remote IP]   File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Mon May 02 16:58:23.849900 2016] [:error] [pid 16839] [remote IP]     apps.populate(settings.INSTALLED_APPS)
[Mon May 02 16:58:23.849920 2016] [:error] [pid 16839] [remote IP]   File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
[Mon May 02 16:58:23.850096 2016] [:error] [pid 16839] [remote IP]     app_config.import_models(all_models)
[Mon May 02 16:58:23.850125 2016] [:error] [pid 16839] [remote IP]   File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
[Mon May 02 16:58:23.850224 2016] [:error] [pid 16839] [remote IP]     self.models_module = import_module(models_module_name)
[Mon May 02 16:58:23.850246 2016] [:error] [pid 16839] [remote IP]   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Mon May 02 16:58:23.850303 2016] [:error] [pid 16839] [remote IP]     __import__(name)
[Mon May 02 16:58:23.850324 2016] [:error] [pid 16839] [remote IP]   File "/usr/local/env/project/config/models.py", line 10, in <module>
[Mon May 02 16:58:23.851120 2016] [:error] [pid 16839] [remote IP]     from webui.models import Change
[Mon May 02 16:58:23.851181 2016] [:error] [pid 16839] [remote IP] ImportError: No module named models
[Mon May 02 16:58:23.851589 2016] [ssl:debug] [pid 16850] ssl_engine_io.c(992): [client IP:29158] AH02001: Connection closed to child 1 with standard shutdown (server server:443)

答案 1 :(得分:0)

在您的情况下,您需要Intent i = new Intent(LoginActivity.this, RegisterActivity.class);

LoginActivity.this指向您当前所处活动的实例,并且在使用动态内部类时使用它,就像您的情况一样。

this适用于您当前的对象。

我不是那么好的老师,希望你理解它。