Android:无法调用buttonOnCklick

问题描述 投票:-1回答:3

实际上我不明白为什么它没有看到buttonOnClick侦听器?

public class GeneralActivity extends AppCompatActivity {
    // with or without these lines below 
    private View.OnClickListener buttonOnClick = this.buttonOnClick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GlobalData.getInstance().gContext = this;
        setContentView(R.layout.activity_general);
        ((TextView) findViewById(R.id.licence)).setText(MySettings.Values().LicenceNo);
        Button connect = (Button)findViewById(R.id.connect);
        connect.setOnClickListener(buttonOnClick);
        Button send = (Button)findViewById(R.id.sendall);
        send.setOnClickListener(buttonOnClick);
    }

    boolean clicked = false;
    public static String LICENCE = "";

    public void buttonOnClick(View v) {
        MessageBox.Show("Connect me");
        Button b = (Button) v;
        if (b.getId() == R.id.connect) {
            MessageBox.Show("Connect me");
                return;

另外,在GeneralActivitry设计器中,所有内容都被写出-两个按钮的onClick,此方法称为GeneralActivity。

请看电影,告诉我现在怎么了?youtube.com/watch?v=heD9QGKtusY&feature=youtu.be

一般活动布局的完整代码:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android">

            <EditText
                android:id="@+id/licence"
                android:layout_width="match_parent"
                android:layout_height="30pt"
                android:ems="10"
                android:hint="1SAT"
                android:inputType="textPersonName"
                android:layout_weight="0"
                android:singleLine="true"
                android:text="SATEST LICENCE NUMBER" />

    <Button
        android:id="@+id/connect"
        android:layout_width="match_parent"
        android:layout_height="30pt"
        android:layout_weight="0"
        android:onClick="buttonOnClick"
        android:text="CONNECT" />

    <LinearLayout
        android:id="@+id/messages"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical" />

    <Button
        android:id="@+id/sendall"
        android:layout_width="match_parent"
        android:layout_height="30pt"
        android:layout_weight="0"
        android:enabled="false"
        android:onClick="buttonOnClick"
        android:text="SEND2ALL" />

嗯,我不完全喜欢这个网站是因为那种人没有任何理由设置-1。他们只喜欢那些页面上的碎屑。我用MAXIMUM示例甚至VIDEO解释了我的问题。您还需要什么其他信息才能弄清楚问题?白痴。

确定,让他们生活,这是该网站所有者的狗屎政策。

现在您仔细阅读了我的错误是什么:

[当我实现OnViewListener接口时,我忘了用@Override标记方法onClick,另一个“大”错误是我从大写字母O nClick编写的处理程序名称onClick。

实际上,这是我的主要错误。在这里发布我的Q之前,我尝试自己理解所有内容,并尝试了家伙给我的所有建议。

字母O和o

  • 嗯,你明白)))

我从事软件开发工作已有30年,而这些错误是我遇到的最困难的错误。像方括号[{jr(..

谢谢大家的帮助。我将答案设置为第一个。再次感谢您。

实际上,我不明白为什么看不到buttonOnClick侦听器?公共类GeneralActivity扩展了AppCompatActivity {//在私有视图下面有无这些行。...

android buttonclick
3个回答
1
投票

Option-1:


0
投票

您可以使用内置的OnClick方法为您完成此操作:这是一个操作方法的示例


0
投票

解决方案:

© www.soinside.com 2019 - 2024. All rights reserved.