O
O
Octavia Melody2015-10-27 15:09:03
Android
Octavia Melody, 2015-10-27 15:09:03

How to open text documents in my application?

Hello again.
The question is simple. How can I open text documents from the file manager in my application's EditText?
That's the way it is here .
Here is my MainActivity:

import android.app.Activity;
        import android.graphics.Color;
        import android.os.Bundle;
        import android.support.v7.app.ActionBarActivity;
        import android.text.Editable;
        import android.text.TextWatcher;
        import android.widget.Button;
        import android.widget.EditText;
        import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    //Widget GUI
    EditText txtStatus;
    TextView lblCount;
    Button btnTweet;

    // Init Static Members
    static int MIN_COUNT = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Init Widget GUI
        txtStatus = (EditText)findViewById(R.id.txtStatus);
        lblCount = (TextView)findViewById(R.id.lblCount);

        // Attached Listener to Edit Text Widget
        txtStatus.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub

            }

            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
                // TODO Auto-generated method stub

            }

            public void afterTextChanged(Editable s) {

                // Display Remaining Character with respective color
                int count = MIN_COUNT + s.length();
                lblCount.setText(Integer.toString(count));
                if(count < 0);
            }
        });

    }

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="#fff">

    <LinearLayout android:id="@+id/linearLayout1"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:touchscreenBlocksFocus="false">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Кількість символів:"
            android:id="@+id/textView" />

        <TextView android:id="@+id/lblCount" android:text="0"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_gravity="right" android:layout_width="wrap_content"
            android:paddingRight="10dp"
            android:layout_weight="1" android:layout_height="match_parent"
            android:gravity="right|center" ></TextView>
    </LinearLayout>

    <EditText android:layout_width="match_parent"
        android:layout_height="match_parent" android:layout_weight="0"
        android:id="@+id/txtStatus">
        <requestFocus></requestFocus>
    </EditText>

</LinearLayout>

Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-10-27
@OctaviaMelody

developer.android.com/intl/en/training/basics/inte...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question