zoukankan      html  css  js  c++  java
  • 统计字符数,行数

    统计字符数,行数#

    第一版(错版)##

    刚开始接触这个任务,第一反应是 一个监听搞定;
    下面附上代码:
    ""

    <EditText
        android:id="@+id/edt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入" />
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/text"
        android:text="显示"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/show"/>
    
    "" 逻辑部分代码: "" EditText et; TextView tv, show; int text_length; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
        et = (EditText) findViewById(R.id.edt);
        tv = (TextView) findViewById(R.id.text);
        show = (TextView) findViewById(R.id.show);
    
        show.setText("已经输入了" + text_length);
        et.addTextChangedListener(new TextWatcher() {
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                show.setText("已经输入了" + text_length);
            }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
                show.setText("已经输入了" + text_length);
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
                show.setText("已经输入了" + text_length);
            }
        });
    }""
    

    通过对edittext的监听,判断目前输入的字符数。
    ‘但是我认真理解下这个任务,实际上的任务和自己写代码有了千差万别’
    这个任务,
    1.需要统计的是文本的字符数;
    2.需要对文本进行解析;
    3.标点符号算不算字符(网上查后,是属于字符,ps:并占用一个字符)

    第二版##

    首先,权限
    """"
    逻辑
    预先创建好readme文本文件
    打开文件并加载到editview上,然后进行统计;
    ""et = (EditText) findViewById(R.id.edt);
    tv = (TextView) findViewById(R.id.text);
    show = (TextView) findViewById(R.id.show);

        show.setText("已经输入了" + text_length);
        btn=(Button)findViewById(R.id.btn_bbb);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bbb();
            }
        });
        et.addTextChangedListener(new TextWatcher() {
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                show.setText("已经输入了" + text_length);
            }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
                show.setText("已经输入了" + text_length);
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
                show.setText("已经输入了" + text_length);
            }
        });""
    

    ""
    StringBuffer sb = new StringBuffer();
    File file = new File("storage/ECAF-4B9A/readme.txt");
    try {
    BufferedReader br = new BufferedReader(new FileReader(file));
    String line = "";
    while ((line = br.readLine()) != null) {
    sb.append(line);
    }
    br.close();
    show.setText(sb.toString());
    } catch (IOException e){
    e.printStackTrace();
    }
    ""
    这样写,但运行时,没有反应,
    提示
    可能是权限的问题,解决中。
    要是有急需解答的朋友,推荐
    [http://www.cnblogs.com/qq714081644/p/6616566.html]
    最后附上:

  • 相关阅读:
    浅谈欧拉定理的证明
    10-8 王小呆的校内互坑赛题解
    10-8 王小呆的校内互坑赛题面
    线段树 洛谷P3932 浮游大陆的68号岛
    BFS+最小生成树+倍增+LCA【bzoj】4242 水壶
    洛谷P1119 灾后重建
    border-radius:50%和100%的区别
    react-native Android release打包失败
    关于react理解的文章
    atom常用快捷键-mac亲测
  • 原文地址:https://www.cnblogs.com/firefoxman/p/6628445.html
Copyright © 2011-2022 走看看