I
I
Ilya Megalinskiy2015-06-04 10:57:47
Android
Ilya Megalinskiy, 2015-06-04 10:57:47

How can I get help in the application?

Hello! I need to make help for the application. I don't know how to upload a text file to a project in android stuio. I have a text file in my "raw" project folder.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kaktus Team, 2015-06-04
@KaktusTeam

Good afternoon,
You can open a stream and read data from this file like this:
Resources resources = getResources(); // if from a fragment then getActivity().getResources()
InputStream is = resources.openRawResource(R.raw.my_help_file))
Here are the docks
Good luck!

A
Alexander, 2015-06-04
@NeiroNx

I made a dialog with a WebView and loaded HTML from assets :

public class HelpDialog extends DialogFragment{
        @Override
        public Dialog onCreateDialog(Bundle savedInstanseState){
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            // Get the layout inflater
            LayoutInflater inflater = getActivity().getLayoutInflater();
            @SuppressLint("InflateParams") final View Help = inflater.inflate(R.layout.help, null, false);
            assert Help!=null;
            final WebView helpText = (WebView)Help.findViewById(R.id.helpText);
            helpText.loadUrl("file:///android_asset/"+getString(R.string.help_dir)+"/index.html");
            ImageButton prew = (ImageButton)Help.findViewById(R.id.help_prew);
            ImageButton next = (ImageButton)Help.findViewById(R.id.help_next);
            ImageButton home = (ImageButton)Help.findViewById(R.id.help_home);
            prew.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    helpText.goBack();
                }
            });
            next.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    helpText.goForward();
                }
            });
            home.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    helpText.loadUrl("file:///android_asset/"+getString(R.string.help_dir)+"/index.html");
                }
            });
            // Inflate and set the layout for the dialog
            // Pass null as the parent view because its going in the dialog layout
            builder.setView(Help)
                    // Add action buttons
                    .setPositiveButton(R.string.action_quit, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            HelpDialog.this.getDialog().cancel();
                        }
                    });
            return builder.create();

        }
    }

and fragment resource code
<?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">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/help_prew"
            android:src="@android:drawable/ic_media_previous" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/help_next"
            android:src="@android:drawable/ic_media_next" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/help_home"
            android:src="@android:drawable/ic_menu_help" />
    </LinearLayout>

    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/helpText"
        android:focusableInTouchMode="false" />
</LinearLayout>

Screen output like this:
DialogFragment help = new HelpDialog();
                help.show(getSupportFragmentManager(),"help");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question