小编Sat*_*CyB的帖子

将大文本文件读入Textview

我想从SD卡读取大文件到文本视图.我有想法,但我不知道如何申请.

我认为这个东西需要使用:Handler And Thread

但我不知道如何申请.任何人都举一些例子或教程.

更新:

Thread test=new Thread()
    {
        public void run()
        {
    File sfile=new File(extras.getString("sfile"));
    try {
        StringBuilder text = new StringBuilder();
        BufferedReader br = new BufferedReader(new FileReader(sfile));
        String line1;
        while(null!=(line1=br.readLine()))
        {
            text.append(line1);
            text.append("\n");
        }
        subtitletv.setText(text.toString());

    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
        }
    };
    test.start();
Run Code Online (Sandbox Code Playgroud)

这是我的代码.但它比以前的代码更好,但它无法读取2MB文件.如何解决这个问题?以及如何设定进度?

android

6
推荐指数
1
解决办法
8514
查看次数

如何将文件读入textview,并在文本文件中正确显示?

如何将文件读入textview,并在文本文件中正确显示?我可以将文件读入textview.但是在文本文件中显示如下.我的原始文本文件:

Testing this 1

Satheeshisdf sdf asdfsdfasd fasdfsdfsd
i can able to do it.

Trying it                         thats all.`
Run Code Online (Sandbox Code Playgroud)

但显示如下:

i can able to do it.

Trying it                         thats all.`
Run Code Online (Sandbox Code Playgroud)

布局:

<ScrollView 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_weight="1.0">
<TextView 
    android:id="@+id/subtitletv"
    android:textSize="18dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
/>
Run Code Online (Sandbox Code Playgroud)

程序:

subtitletv = (TextView)findViewById("R.id.t");
try {
        FileReader fr=new FileReader(selectedfile);
        BufferedReader br=new BufferedReader(fr);
        String line = null;
        try {
            while(br.readLine()!=null)
            {
                line =br.readLine();
                subtitletv.append(line);
                subtitletv.append("\n");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch …
Run Code Online (Sandbox Code Playgroud)

android textview

1
推荐指数
1
解决办法
8192
查看次数

活动在轮换时关闭

我的活动正在接近轮换.不知道为什么?

此外,我检查了这个问题: 在Android上旋转活动重启 但无法找到解决方案.

这是我的oncreate函数:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.manage);


    //Defining and Getting Saved Preferences
    data=getSharedPreferences("cybapps", 0);
    dataeditor=data.edit();

    //To Delete all Preferences
    dataeditor.clear();
    dataeditor.commit();

   //Declaration 

    btn_delete=(Button)findViewById(R.id.btn_delete);
    btn_schedule=(Button)findViewById(R.id.btn_schedule);
    btn_deschedule=(Button)findViewById(R.id.btn_deschedule);
    profilelist=(ListView)findViewById(R.id.profilelist);
    am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
    status=(TextView)findViewById(R.id.status);
    random=new Random(); 

   btn_delete.setOnClickListener(this);
    btn_schedule.setOnClickListener(this);
    btn_deschedule.setOnClickListener(this);

  //Listout all profiles
    listout();
}
Run Code Online (Sandbox Code Playgroud)

android rotation android-activity

0
推荐指数
1
解决办法
258
查看次数

标签 统计

android ×3

android-activity ×1

rotation ×1

textview ×1