草庐IT

android - 我可以得到编辑文本离开事件吗

coder 2023-11-24 原文

我希望在 Edittext 离开事件后将 edittext“文本”反射(reflect)在 textview 上是否有可能在 android 中我尝试过这个可以有人告诉我有什么问题或它在 android 中不可能吗?

我尝试了所有可能的事件

objNextbet=getNextBets();
            Button btnbetNow =(Button)findViewById(R.id.btnBetNow);
            try
            {
            SimpleExpandableListAdapter expListAdapter =
                new SimpleExpandableListAdapter(
                    this,
                    createBetGroupList("next"), // groupData describes the first-level entries
                    R.layout.group_row, // Layout for the first-level entries
                    new String[] { "BetGroup" },    // Key in the groupData maps to display
                    new int[] { R.id.childname },       // Data under "colorName" key goes into this TextView
                    createBetChildList("next") ,    // childData describes second-level entries
                    R.layout.child_row, // Layout for second-level entries
                    new String[] { "betText","betRate","betID" },   // Keys in childData maps to display
                    new int[] { R.id.txtBetText, R.id.txtdecRate,R.id.txtstrBetID}  // Data under the keys above go into these TextViews

                ) {
                @Override 
                public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
                {          
                     final View childview = super.getChildView(groupPosition, childPosition,isLastChild, convertView, parent); 


                     final TextView txtBetText = (TextView)childview.findViewById(R.id.txtBetText);
                     final TextView txtstrBetID = (TextView)childview.findViewById(R.id.txtstrBetID);
                     final TextView txtdecRate = (TextView)childview.findViewById(R.id.txtdecRate);                  


                     String strBetGroup="";
                     for(int n = 0 ; n < objNextbet.size() ; n++ ) 
                        {
                         if(objNextbet.get(n).getBetText().toString().equals(txtBetText.getText().toString()))
                          {
                             strBetGroup=objNextbet.get(n).getstrBetGroupName().toString();
                          }
                        }



                     Button btnBetNow = (Button)childview.findViewById(R.id.btnBetNow);
                     btnBetNow.setTag(txtBetText.getText() + "-" +
                             txtstrBetID.getText() +"-" +txtdecRate.getText()+"-"+strBetGroup);

                     btnBetNow.setOnClickListener(new OnClickListener() 
                     {    
                        @Override             
                        public void onClick(View view) 
                        {                 
                           try
                           {
                               String TagValue=(String) view.getTag();
                               final String bet[] = TagValue.split("-");

                               final Dialog dialogbetNow = new Dialog(myucontext);
                               /** Disabling The PopUp Title Bar */
                               dialogbetNow.requestWindowFeature(Window.FEATURE_NO_TITLE); 

                               /** Set The Content For The PopUp */
                               dialogbetNow.setContentView(R.layout.popupbet);

                                /** Set The PopUp Deposit Balance */ 
                                  TextView txtCashcredit =(TextView)dialogbetNow.findViewById(R.id.txtCashcredit); 
                                  txtCashcredit.setText(Double.toString(objCGUserProfile.getUsedCredit()).toString());

                                  final TextView txtbetBetText = (TextView)dialogbetNow.findViewById(R.id.txtbetBetText);
                                  txtbetBetText.setText(bet[0]);

                                  TextView txtbetRate = (TextView)dialogbetNow.findViewById(R.id.txtbetRate);
                                  txtbetRate.setText(bet[2]);

                                  Button btnpopupBetNow = (Button)dialogbetNow.findViewById(R.id.btnpopupBetNow);
                                  btnpopupBetNow.setOnClickListener(new OnClickListener()
                              {

                                @Override
                                public void onClick(View v)
                                {

                                    final EditText ETStake = (EditText)dialogbetNow.findViewById(R.id.ETStake);

                                    if(ETStake.getText().toString().equals(""))
                                    {
                                        TextView txtError =(TextView)dialogbetNow.findViewById(R.id.txtError);
                                        txtError.setTextColor(Color.RED);
                                        txtError.setText("Please Enter cash.");
                                    }
                                    else
                                    {
                                        final double cash = Double.valueOf((String)ETStake.getText().toString()).doubleValue();

                                        ETStake.setOnFocusChangeListener(new EditText.OnFocusChangeListener()
                                        {    
                                            @Override
                                            public void onFocusChange(View v,boolean hasFocus) 
                                            {
                                                if (!hasFocus)
                                                {
                                                    // TODO: the editText has just been left 
                                                    TextView txtRisk = (TextView)dialogbetNow.findViewById(R.id.txtRisk);
                                                    TextView txtReturn = (TextView)dialogbetNow.findViewById(R.id.txtReturn);
                                                    txtRisk.setText(Double.toString(cash).toString());
                                                    double stake = Double.parseDouble(ETStake.getText().toString());
                                                    double rate = Double.parseDouble(bet[2]);
                                                    double betReturn = stake * rate;
                                                    txtReturn.setText(Double.toString(betReturn));
                                                }

                                            }
                                        });

                                    }
                                }
                            });

                                  ImageView imgCancel = (ImageView)dialogbetNow.findViewById(R.id.imgCancel);
                                  imgCancel.setOnClickListener(new OnClickListener() {

                                    @Override
                                    public void onClick(View v) 
                                    {
                                         try 
                                         {
                                           dialogbetNow.cancel();   
                                         }
                                         catch (Exception e)
                                         {
                                         }  
                                    }
                                });

                              dialogbetNow.show();

                           }

                           catch(Exception ex)
                           {
                               ex.toString();
                           }
                        } 
                        });                  

                     return childview;     
                } 

最佳答案

您可以在 Activity 的 onCreate 方法内的 EditText 上注册一个 OnFocusChangeListener:

final EditText et = (EditText)findViewById(R.id.my_edit_text);
et.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
    @Override
    public void onFocusChange(View v, boolean hasFocus)
    {
        if (!hasFocus)
            // TODO: the editText has just been left
    }
});

此处 onFocusChangev 参数是您的 EditText 控件。

此外,如果您想在 EditText 内容的每次更改时更新您的 TextView,您应该将更新代码放在 public void afterTextChanged 中(Editable s) 已注册的 TextWatcher 方法。

//确保 txtRisk TextView 是 dialogbetNow View 的一部分。

关于android - 我可以得到编辑文本离开事件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5830995/

有关android - 我可以得到编辑文本离开事件吗的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

  3. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  4. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  5. ruby - 我可以使用 Ruby 从 CSV 中删除列吗? - 2

    查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html

  6. ruby - 如何离开加入Arel? - 2

    Arel3.0.2提供了两个类来指定连接类型:Arel::Nodes::InnerJoin和Arel::Nodes::OuterJoin并使用InnerJoin默认。foo=Arel::Table.new('foo')bar=Arel::Table.new('bar')foo.join(bar,Arel::Nodes::InnerJoin)#innerfoo.join(bar,Arel::Nodes::OuterJoin)#outerfoo.join(bar,???)#left如果要生成左连接,如何连接两个表? 最佳答案 你可以使用

  7. ruby - 我可以使用 aws-sdk-ruby 在 AWS S3 上使用事务性文件删除/上传吗? - 2

    我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的

  8. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  9. ruby - 有人可以帮助解释类创建的 post_initialize 回调吗 (Sandi Metz) - 2

    我正在阅读SandiMetz的POODR,并且遇到了一个我不太了解的编码原则。这是代码:classBicycleattr_reader:size,:chain,:tire_sizedefinitialize(args={})@size=args[:size]||1@chain=args[:chain]||2@tire_size=args[:tire_size]||3post_initialize(args)endendclassMountainBike此代码将为其各自的属性输出1,2,3,4,5。我不明白的是查找方法。当一辆山地自行车被实例化时,因为它没有自己的initialize方法

  10. ruby - 是否可以覆盖 gemfile 进行本地开发? - 2

    我们的git存储库中目前有一个Gemfile。但是,有一个gem我只在我的环境中本地使用(我的团队不使用它)。为了使用它,我必须将它添加到我们的Gemfile中,但每次我checkout到我们的master/dev主分支时,由于与跟踪的gemfile冲突,我必须删除它。我想要的是类似Gemfile.local的东西,它将继承从Gemfile导入的gems,但也允许在那里导入新的gems以供使用只有我的机器。此文件将在.gitignore中被忽略。这可能吗? 最佳答案 设置BUNDLE_GEMFILE环境变量:BUNDLE_GEMFI

随机推荐