• 关于wc项目的简单基本前期制作。


    统计: 字符串 单词 行数#

    首先这题要了解可以进行键盘输入所需要的文本,并对他进行解析。解析得出的结果显示出字符串,行数还有单词量##

    该次项目完成情况不是很好,总结代码的逻辑性不是很规范,存在问题

    布局##

    <TextView
        android:text="测试的项目"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_marginStart="50dp"
        android:id="@+id/tv"/>
    
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_below="@+id/tv"
        android:layout_alignParentStart="true"
        android:layout_marginStart="17dp"
        android:layout_marginTop="12dp"
        android:id="@+id/et"/>
    
    <Button
        android:text="测试"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/et"
        android:layout_alignStart="@+id/et"
        android:layout_marginTop="34dp"
        android:id="@+id/btn_test"/>
    
    <TextView
        android:text="字符数:8单词数:2行数:1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn_test"
        android:layout_alignStart="@+id/btn_test"
        android:layout_marginTop="12dp"
        android:id="@+id/textView2"/>
    

    实现项目##

    package com.example.wc;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;

    import java.io.IOException;
    import java.io.InputStreamReader;

    public class MainActivity extends AppCompatActivity {
    private EditText editText;
    private Button btn_test;
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editText = (EditText)findViewById(R.id.et);
    btn_test = (Button)findViewById(R.id.btn_test );
    textView = (TextView)findViewById(R.id.tv);
    btn_test.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    int charnum = 0 ;//字符
    int words = 0;//单词
    int linenum = 0;//行数
    String filename=editText.getText().toString();
    try {
    //定义一个str
    String str="";
    //打开
    File file = new File(toString(str));
    FileInputStream isr=new FileInputStream(file);
    BufferedReader br = new BufferedReader(new InputStreamReader(isr));
    //解析这个
    while(-1 != br.read()){
    String s = br.readLine();
    charnum +=s.length();
    words +=s.split(" ").length;
    linenum ++;
    }
    isr.close();//关闭
    textView.setText("字符数:"+charnum+" 单词数:"+words+"行 数:"+linenum);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

            private String toString(String str) {
                String str1 = str;
                //定义str里的文本。
                str="kids child";
    
    
                return null;
            }
        });
    }
    

    }

    运行结果##

    个人##

  • 相关阅读:
    基于emWin的WAV,MP3软解软件播放器,带类似千千静听频谱,含uCOS-III和FreeRTOS两个版本
    [Linux-CentOS7]yum清华源CentOS7
    [Python]random生成随机6位验证码
    [Python]公司接口返回值规范
    [MacOS]Chrome 强制刷新
    Mybatis的XML中数字不为空的判断
    康师傅JVM:执行引擎(十二)
    Qt 随机颜色的生成
    Qt QVector常见使用方法
    Qt 判断文件是否存在
  • 原文地址:https://www.cnblogs.com/wangliang96/p/6626240.html
Copyright © 2020-2023  润新知