jjzjj

android - Seterror 信号没有消失并且搜索正在运行

coder 2023-12-10 原文

我已经在两个编辑文本上实现了设置错误的代码。

  • 首先获取任何没有空值或空值的字符串。
  • 其次获取任何没有 null 或空值的字符串,并且必须有一些 Double 值。

代码如下

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SearchPlaces extends Activity {
    EditText place;
    EditText distance;
    Button search;
    static String _place;
    static String _distance;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        place = (EditText) findViewById(R.id.place);
        distance = (EditText) findViewById(R.id.distance);
        search = (Button) findViewById(R.id.search);
        search.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Map<String, String> validate = new HashMap<String, String>();
                _place = place.getText().toString();
                _distance = distance.getText().toString();
                validate.put("placename", _place);
                validate.put("distancenumeric", _distance);
                if (!validateInputInformation(validate)) {
                    return;
                }
                if ((_place == "" && _distance == "")) {
                    Toast.makeText(getApplicationContext(),
                            "Please fill all the information",
                            Toast.LENGTH_SHORT).show();
                } else {
                    _place = place.getText().toString();
                    _distance = distance.getText().toString();
                    Intent placedist = new Intent(getApplicationContext(),
                            MainActivity.class);
                    Bundle bundle = new Bundle();

                    bundle.putString("place", _place);
                    bundle.putString("distance", _distance);

                    placedist.putExtras(bundle);
                    startActivity(placedist);
                }
            }

            private boolean validateInputInformation(
                    Map<String, String> validate) {

                String l_place = validate.get("placename");
                if (l_place == null || l_place.equals("")) {
                    place.setError("Please enter the Place First");
                    return false;
                }

                String l_distance = validate.get("distancenumeric");
                if (l_distance == null || l_distance.equals("")) {
                    distance.setError("Please enter the Distance First");
                    return false;
                }
                if (!isDoubleNumber(l_distance)) {
                    distance.setError("Please enter Numeric Value");
                    return false;
                }

                return true;

            }
            private boolean isDoubleNumber (String num) {
                try {
                    Double.parseDouble(num);
                } catch (NumberFormatException nfe) {
                    return false;
                }
                return true;
            }
        });
    }
}

在实现所有工作后一切正常,但是当我没有输入并单击搜索按钮时,错误会在第一个编辑框中弹出,之后当我重新输入正确的值作为输入时,错误通知不会' 消失了,但搜索按钮工作正常。

请帮助我,以便可以从第一个编辑框中删除设置错误通知。

最佳答案

在代码行下面写而不是 if ((_place == ""&& _distance == "")),它将解决您的问题。

if (_place.equals("") && _distance.equals(""))

关于android - Seterror 信号没有消失并且搜索正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13525343/

有关android - Seterror 信号没有消失并且搜索正在运行的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  3. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  4. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  5. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  6. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  7. ruby - 在没有 sass 引擎的情况下使用 sass 颜色函数 - 2

    我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re

  8. ruby - Sinatra:运行 rspec 测试时记录噪音 - 2

    Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/

  9. ruby-on-rails - Nokogiri:使用 XPath 搜索 <div> - 2

    我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll

  10. ruby-on-rails - 无法让 rspec、spork 和调试器正常运行 - 2

    GivenIamadumbprogrammerandIamusingrspecandIamusingsporkandIwanttodebug...mmm...let'ssaaay,aspecforPhone.那么,我应该把“require'ruby-debug'”行放在哪里,以便在phone_spec.rb的特定点停止处理?(我所要求的只是一个大而粗的箭头,即使是一个有挑战性的程序员也能看到:-3)我已经尝试了很多位置,除非我没有正确测试它们,否则会发生一些奇怪的事情:在spec_helper.rb中的以下位置:require'rubygems'require'spork'

随机推荐