Answer the question
In order to leave comments, you need to log in
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
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!
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();
}
}
<?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>
DialogFragment help = new HelpDialog();
help.show(getSupportFragmentManager(),"help");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question