Android 按钮未对OnClickListener作出反应
我正在制作一个程序,其中一个菜单有四个按钮,其中一个按钮转到另一个有按钮的菜单。第一个屏幕上的按钮工作正常,但在第二个屏幕上,按下按钮时什么都不做。我对它们进行了同样的编程,但我不明白为什么按钮不起作用。当我按下它们时,LogCat或控制台上没有显示任何内容 XML文件Android 按钮未对OnClickListener作出反应,android,onclicklistener,Android,Onclicklistener,我正在制作一个程序,其中一个菜单有四个按钮,其中一个按钮转到另一个有按钮的菜单。第一个屏幕上的按钮工作正常,但在第二个屏幕上,按下按钮时什么都不做。我对它们进行了同样的编程,但我不明白为什么按钮不起作用。当我按下它们时,LogCat或控制台上没有显示任何内容 XML文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/orangebackground"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="System"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="@+id/softwarewords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Software"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/hardwarewords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Hardware"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/logswords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/system2"
android:layout_centerVertical="true"
android:text="Logs"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/system1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/hardwarewords"
android:layout_alignParentLeft="true"
android:background="@drawable/box" />
<Button
android:id="@+id/system3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/system1"
android:layout_alignBottom="@+id/system1"
android:layout_alignRight="@+id/softwarewords"
/>
<Button
android:id="@+id/system2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/system3"
android:layout_alignBottom="@+id/system3"
android:layout_marginLeft="26dp"
android:layout_toRightOf="@+id/system3"
android:background="@drawable/systemlog" />
</RelativeLayout>
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/background1"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SystemMenu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.SYSTEMMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialTwo"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.TUTORIALTWO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialThree"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.TUTORIALTHREE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialFour"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.TUTORIALFOUR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".LogsText"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.LogsText" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".HardwareText"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.HARDWARETEXT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SoftwareText"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.SOFTWARETEXT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
菜单系统
活动类不在清单中,如何启动此活动。可能你上错班了,请检查一下
还有一点,请不要用小写字母开头你的类名。哪一个是你说的
第二个屏幕
?试试这个startActivity(newintent(这个,LogsText.Class))代码>对于sys2
单击事件并还原。XML文件是第二个screen@Ullas您不能在那里使用此
。它需要是ActivityName。这个但是v.getContext()
会更好。@user3795146阅读了我之前关于不使用这个
的评论,我添加到清单中,但它没有改变任何东西
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/background1"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SystemMenu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.SYSTEMMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialTwo"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.TUTORIALTWO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialThree"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.TUTORIALTHREE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialFour"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.TUTORIALFOUR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".LogsText"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.LogsText" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".HardwareText"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.HARDWARETEXT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SoftwareText"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.tutorial.SOFTWARETEXT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>