I'm creating an app that contains a "Tip of the Day" feature. This is essentially a pop-up, activated by a button. It currently has filler text right now, but I am trying to create a way in which a text file (stored in src/main/assets) is read, and an individual line is displayed in the pop-up. How can I do this? These lines in the text file are individualized by the return key. I will find a way to display unique tips each time the button is clicked, but I will get to that part later.
Here is the code for the pop-up itself:
public class homeFragmentDialog extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setMessage("Filler text.");
builder1.setCancelable(true);
builder1.setPositiveButton(
"Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
}
And just in case, here is the fragment file which holds the button that activates the previous activity:
public class homeFragment extends Fragment {
View rootView;
private Button button0;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_home, container, false);
button0 = (Button) rootView.findViewById(R.id.buttonDialog);
button0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), homeFragmentDialog.class);
startActivity(intent);
}
});
return rootView;
}
}