For-Loop在Text-watcher中返回false值

时间:2013-10-09 10:15:24

标签: android for-loop textwatcher

问题发生了变化:

在我的应用程序中,我需要检查字符串值以及字符串数组的所有值;

我使用此代码检查从i = 0到i = 4的值;

public void onCreate(Bundle savedInstanceState)
{
      ...
 ArrayList<String> ch= new ArrayList<String>();
    ch.add("س");
    ch.add("ل");
    ch.add("ا");
    ch.add("م");
      ...
 } 

但是这个循环只返回最后一个值 - (i = 4)并且不添加i值添加剂。

  private final TextWatcher TextWatcher_Method = new TextWatcher() 
    {   
     public void onTextChanged(CharSequence arg0, int start, int befor, int count) 
        {

          String matn = "Edit-Text String";
          int fa_cnt=0;

        for (int i=0;i<4;i++)
          {
           if(matn.contains(ch.get(i)))
            {
                fa_cnt=4;
            } 
            else
            {
                fa_cnt=8;
            }
          } 

        }
     }

但是这个循环,在TextWatcher的外部做对了。

5 个答案:

答案 0 :(得分:0)

您是否在清单文件中添加了互联网权限?

答案 1 :(得分:0)

您是否在清单文件中提供了INTERNET权限?

   <uses-permission android:name="android.permission.INTERNET" />

答案 2 :(得分:0)

@saeid将webview添加到main.xml并使用Internet权限更新AndroidManiferst.xml

<uses-permission android:name="android.permission.INTERNET" />

//在loadurl和browser =

之间添加
    browser.getSettings().setJavaScriptEnabled(true);

答案 3 :(得分:0)

handling page navigation

查看Android文档的内容
  

如果您想要更好地控制点击链接的加载位置,请创建一个覆盖shouldOverrideUrlLoading()方法的WebViewClient。例如:

private class MyWebViewClient extends WebViewClient {

  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (Uri.parse(url).getHost().equals("www.example.com")) {
        // This is my web site, so do not override; let my WebView load the page
        return false;
    }
    // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    return true;
  }
}

在您的情况下,函数中的代码应为view.loadURL(url)。 从你的onCreate添加browser.setWebViewClient(new WebViewClient());

答案 4 :(得分:0)

行 我用以下代码解决了这个问题:

首先我声明一个这样的数组:

CharSequence it[]={"آ","ا","ب","پ","ت","ث","ج","چ","ح","خ","د","ذ",
        "ر","ز","ژ","س","ش","ص","ض","ط","ظ","ع","غ","ف","ق"
        ,"ک","گ","ل","م","ن","و","ه","ی","ء"};

然后在TextWatcher中写下以下代码:

     private final TextWatcher TextWatcher_Method = new TextWatcher() 
         {  
            public void onTextChanged(CharSequence arg0, int start, int  befor,int count) {}

            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {}

            public void afterTextChanged(Editable arg0)
              {
                fa_cnt=8;
                TextView counter=(TextView)findViewById(R.id.txt_counter);
                String matn =matn_counter.getText().toString();

               for (int i=0;i<it.length;i++)
                {
                    if(matn.contains(it[i]))
                    {
                        fa_cnt=4;
                    }
                }
            cnt2=matn_counter.length();
            cnt1=(int) Math.ceil(cnt2/fa_cnt);
            Integer cnt3=(cnt2%fa_cnt);

            counter.setText(Integer.toString(cnt1)+"/"+Integer.toString(cnt3));

            }
       } 

此代码在编辑文本中检测到包含波斯语(Parsi-Farsi-Iran)字母或不包含!