这是我的代码。它非常简单,但是当我点击按钮“button1”时,没有任何反应。我做错了什么?
public class TestTab extends Activity {
Button button1;
Intent i;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.btnScore);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "On Click Event", 5000).show();
//i = new Intent(TestTab.this, AndroidTab.class);
//startActivity(i);
}
});
}}
第二--
package com.example.picturegame2;
import android.app.TabActivity;
public class AndroidTab extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tabzz);
TabHost tabHost = getTabHost();
TabSpec localspec = tabHost.newTabSpec("Local");
localspec.setIndicator("Local", getResources().getDrawable(R.drawable.friend));
Intent localIntent = new Intent(this, local.class);
localspec.setContent(localIntent);
TabSpec worldwidespec = tabHost.newTabSpec("worldwide");
worldwidespec.setIndicator("Worldwide", getResources().getDrawable(R.drawable.worldwide));
Intent worldwideIntent = new Intent(this, worldwide.class);
worldwidespec.setContent(worldwideIntent);
tabHost.addTab(worldwidespec);
tabHost.addTab(localspec);
}
}
第三--
package="com.example.picturegame2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".local"/>
<activity android:name=".AndroidTab"/>
<activity android:name=".TestTab"/>
<activity android:name=".tabzz"/>
<activity android:name=".worldwide"/>
</application>
布局--
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Start New Game"
android:id="@+id/BtnGame"
android:textSize="35dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
/>
<ListView
android:id="@+id/LsOpenGames"
android:layout_width="250dp"
android:layout_height="210dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="130dp"
></ListView>
<Button
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Profile"
android:id="@+id/btnProfile"
android:textSize="15dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="375dp"
/>
<Button
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Score"
android:id="@+id/btnScore"
android:textSize="15dp"
android:layout_marginLeft="170dp"
android:layout_marginTop="375dp"
/>
</RelativeLayout>
新的 Logcat: 11-29 12:15:39.552: D/gralloc_goldfish(613): 没有检测到 GPU 模拟的模拟器。 11-29 12:15:40.062:我/编舞(613):跳过了 51 帧!应用程序可能在其主线程上做了太多工作。 11-29 12:16:08.902:我/编舞(613):跳过了 30 帧!应用程序可能在其主线程上做了太多工作。
最佳答案
你必须像这样删除全局声明的 Intent 变量,
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.btnScore);
button1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(TestTab.this, AndroidTab.class);
startActivity(i);
}
});
}
或者试试这个,
Button button1;
Intent i;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.btnScore);
button1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
i = new Intent(TestTab.this, AndroidTab.class);
startActivity(i);
}
});
}
您的 startActivity(i) 可能引用了全局声明的 Intent 变量,您忘记初始化并在本地创建了一个 Intent 对象与全局声明的名称相同的名称“i”。
如果上述想法对您没有帮助,那么正如用户 Yajneshwar Mandal 所建议的那样,您需要尝试一下。或者在ClickListener里面放个日志,看看控件有没有进去。
关于Android, Intent 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13562337/
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o
这段代码似乎创建了一个范围从a到z的数组,但我不明白*的作用。有人可以解释一下吗?[*"a".."z"] 最佳答案 它叫做splatoperator.SplattinganLvalueAmaximumofonelvaluemaybesplattedinwhichcaseitisassignedanArrayconsistingoftheremainingrvaluesthatlackcorrespondinglvalues.Iftherightmostlvalueissplattedthenitconsumesallrvaluesw
你能解释一下吗?我想评估来自两个不同来源的值和计算。一个消息来源为我提供了以下信息(以编程方式):'a=2'第二个来源给了我这个表达式来评估:'a+3'这个有效:a=2eval'a+3'这也有效:eval'a=2;a+3'但我真正需要的是这个,但它不起作用:eval'a=2'eval'a+3'我想了解其中的区别,以及如何使最后一个选项起作用。感谢您的帮助。 最佳答案 您可以创建一个Binding,并将相同的绑定(bind)与每个eval相关联调用:1.9.3p194:008>b=binding=>#1.9.3p194:009>eva
我无法运行Spring。这是错误日志。myid-no-MacBook-Pro:myid$spring/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/lib/spring/sid.rb:17:in`fiddle_func':uninitializedconstantSpring::SID::DL(NameError)from/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/li
我在RoR应用程序中有一个提交表单,是使用simple_form构建的。当字段为空白时,应用程序仍会继续下一步,而不会提示错误或警告。默认情况下,这些字段应该是required:true;但即使手动编写也行不通。该应用有3个步骤:NewPost(新View)->Preview(创建View)->Post。我的Controller和View的摘录会更清楚:defnew@post=Post.newenddefcreate@post=Post.new(params.require(:post).permit(:title,:category_id))ifparams[:previewButt
我一直在Heroku上尝试不同的缓存策略,并添加了他们的memcached附加组件,目的是为我的应用程序添加Action缓存。但是,当我在我当前的应用程序上查看Rails.cache.stats时(安装了memcached并使用dalligem),在执行应该缓存的操作后,我得到current和total_items为0。在Controller的顶部,我想缓存我有的Action:caches_action:show此外,我修改了我的环境配置(对于在Heroku上运行的配置)config.cache_store=:dalli_store我是否可以查看其他一些统计数据,看看它是否有效或我做错
我在我的机器上安装了ruby版本1.9.3,并且正在为我的个人网站开发一个octopress项目。我为我的gems使用了rvm,并遵循了octopress.org记录的所有步骤。但是我在我的rake服务器中发现了一些错误。这是我的命令日志。Tin-Aung-Linn:octopresstal$ruby--versionruby1.9.3p448(2013-06-27revision41675)[x86_64-darwin12.4.0]Tin-Aung-Linn:octopresstal$rakegenerate##GeneratingSitewithJekyllidenticals
我是RubyonRails的新手,我正在尝试编写一个morethan表达式:5%>大于号不断抛出异常捕获错误。我不确定如何解决这个问题?编辑:这不是rails,也不是View,它是一个Ruby构造 最佳答案 使用5%>错误来自photo_limit而不是从Integer延伸类(猜测它真的是一个字符串),因此没有混合比较方法/s有关更多信息,请参阅:http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/特别是你必须混入Comparable并定义方法。虽然在这