所以我的应用中有一个按钮和一个编辑文本。当我单击按钮并在编辑文本中写入内容时, TextView 会发生变化。除了一件事之外,一切都按原样进行。我必须单击按钮两次才能使其工作(仅在我第一次打开 Activity 时)。打开 Activity 后,我第一次按下按钮并没有任何反应,之后它就可以正常工作了。
我已经对此进行了研究,据我所知,造成麻烦的是注意力,但我尝试了一些方法,但没有任何效果。
按钮 XML 代码:
<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignLeft="@+id/checkBox25"
android:text="@string/addMaterial"
android:onClick="submitQuantityButton" >
</Button>
Edittext XML 代码:
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/spinner1"
android:ems="3"
android:inputType="number"
android:maxLength="3" >
</EditText>
我尝试将 android:focusableInTouchMode="false"添加到按钮 XML,我还尝试将 requestFocus 添加到按钮 XML,但它仍然不起作用。我还从 edittext 中删除了 requestFocus ,但它不起作用。我已经没有什么可以尝试的想法了。
onClick 方法:
public void submitQuantityButton (View v){
Button submitButton = (Button)findViewById(R.id.submitButton);
final Spinner sItems = (Spinner)findViewById(R.id.spinner1);
final Context context = this;
final CheckBox cb4 = (CheckBox) findViewById(R.id.checkBox4);
final CheckBox cb5 = (CheckBox) findViewById(R.id.checkBox5);
final CheckBox cb33 = (CheckBox) findViewById(R.id.checkBox33);
final CheckBox cb30 = (CheckBox) findViewById(R.id.checkBox30);
final CheckBox cb6 = (CheckBox) findViewById(R.id.checkBox6);
final CheckBox cb7 = (CheckBox) findViewById(R.id.checkBox7);
final CheckBox cb9 = (CheckBox) findViewById(R.id.checkBox9);
final CheckBox cb10 = (CheckBox) findViewById(R.id.checkBox10);
final CheckBox cb11 = (CheckBox) findViewById(R.id.checkBox11);
final CheckBox cb12 = (CheckBox) findViewById(R.id.checkBox12);
//
final AlertDialog.Builder emptyETextErrorBuilder = new AlertDialog.Builder(context);
emptyETextErrorBuilder.setTitle("Warning");
emptyETextErrorBuilder.setMessage("Please enter a value before pressing this button");
emptyETextErrorBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int position = sItems.getSelectedItemPosition();
EditText quantityEditText = (EditText)findViewById(R.id.editText1);
switch (position){
case 0:
AlertDialog.Builder spinnerErrorBuilder = new AlertDialog.Builder(context);
spinnerErrorBuilder.setTitle("Warning");
spinnerErrorBuilder.setMessage("Please choose an item from the list above and then enter a certain value");
spinnerErrorBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog spinnerError = spinnerErrorBuilder.create();
spinnerError.show();
break;
case 1:
String item1 = quantityEditText.getText().toString();
if (item1.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb4.setText("Elaborate Totem (" + item1 + "/250)");
}
break;
case 2:
String item2 = quantityEditText.getText().toString();
if (item2.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb5.setText("Pile of Crystalline Dust (" + item2 + "/250)");
}
break;
case 3:
String item3 = quantityEditText.getText().toString();
if (item3.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb33.setText("Pile of Crystalline Dust (" + item3 + "/250)");
}
break;
case 4:
String item4 = quantityEditText.getText().toString();
if (item4.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb30.setText("Pile of Crystalline Dust (" + item4 + "/250)");
}
break;
case 5:
String item5 = quantityEditText.getText().toString();
if (item5.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb6.setText("Powerful Venom Sac (" + item5 + "/250)");
}
break;
case 6:
String item6 = quantityEditText.getText().toString();
if (item6.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb7.setText("Vial of Powerful Blood (" + item6 + "/250)");
}
break;
case 7:
String item7 = quantityEditText.getText().toString();
if (item7.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb9.setText("Ancient Bone (" + item7 + "/250)");
}
break;
case 8:
String item8 = quantityEditText.getText().toString();
if (item8.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb10.setText("Armored Scale (" + item8 + "/250)");
}
break;
case 9:
String item9 = quantityEditText.getText().toString();
if (item9.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb11.setText("Vicious Claw (" + item9 + "/250)");
}
break;
case 10:
String item10 = quantityEditText.getText().toString();
if (item10.matches(""))
{
AlertDialog emptyETextError = emptyETextErrorBuilder.create();
emptyETextError.show();
}
else
{
cb12.setText("Vicious Fang (" + item10 + "/250)");
}
break;
}
}
});
}
最佳答案
我的问题是 Button XML 定义:
android:focusableInTouchMode="true"
去掉这个属性,按钮就不需要被触摸两次了。似乎第一次触摸被用于将焦点分配在按钮上,第二次触摸然后触发 OnClickListener。
请注意,使用 android:focusable="true" 属性的 Button 可以正常工作。
关于java - 我必须单击该按钮两次才能使其工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17261876/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
使用Ruby1.9.2运行IDE提示说需要gemruby-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht