---
Developing MyQuiz Apps Part 4
Using ADT 18 On Win 7
CREATING HELP SCREEN
0) Continue from previous tutorial
Or download startup file
1) Edit Layout File
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/bckgrnd">
<TextView
android:id="@+id/TextView01"
android:layout_height="wrap_content"
android:text="@string/help"
android:textSize="40dp"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="10"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal|center"
android:shadowColor="@android:color/white"
android:textColor="#f0f0f0">
</TextView>
<TextView
android:id="@+id/TextView_HelpText"
android:textColor="@android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:isScrollContainer="true"
android:textStyle="italic"
android:drawablePadding="5dp"
android:textColorLink="#FFFF0F"
android:linksClickable="true"
android:fadingEdgeLength="25dp"
android:fadingEdge="vertical"
android:scrollbars="vertical"
android:padding="20dp"
android:textSize="7pt"
android:scrollbarStyle="outsideOverlay"
android:bufferType="spannable"></TextView>
</LinearLayout>
|
File name: MyQuiz/res/layout/help.xml
2) Edit Java File
package com.example.myquiz;
import android.app.Activity;
public class QuizActivity extends Activity {
public static final String GAME_PREFERENCES = "GamePrefs";
public static final String DEBUG_TAG = "MYQUIZ";
}
|
File name: QuizActivity.java
package com.example.myquiz;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class QuizHelpActivity extends QuizActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
// Read raw file into string and populate TextView
InputStream iFile = getResources().openRawResource(R.raw.quizhelp);
try {
TextView helpText = (TextView) findViewById(R.id.TextView_HelpText);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
Log.e(DEBUG_TAG, "InputStreamToString failure", e);
}
}
/**
* Converts an input stream to a string
*
* @param is
* The {@code InputStream} object to read from
* @return A {@code String} object representing the string for of the input
* @throws IOException
* Thrown on read failure from the input
*/
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = null;
while ((strLine = dataIO.readLine()) != null) {
sBuffer.append(strLine + "\n");
}
dataIO.close();
is.close();
return sBuffer.toString();
}
}
|
File name: QuizHelpActivity.java
3) Create Raw Text File
3.1) Add a new folder raw to res folder.
3.2) Add a text file
MyQuiz is a quiz app dedicated to those who love travel and adventure.
By answering a series of Yes or No questions, you gain points toward being the most well-traveled and field-tested person on the planet. Share your experiences and compete with your friends.
MyQuiz was developed by Me.
Phone: 012-3456789
Email: support@me.com
Website: http://www.me.com
Address: 1060 Beach Street, Penang Island.
COPYRIGHT (c) 2014, ME.
All rights reserved.
|
File name: res/raw/quizhelp.txt
No comments:
Post a Comment