Read a text file present in raw folder in android
package com.quiz;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import android.os.Bundle;
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);
InputStream ios = getResources().openRawResource(R.raw.help);
TextView tv = (TextView)findViewById(R.id.textViewhelp);
String strfine = inputStreamToString(ios);
tv.setText(strfine);
}
private String inputStreamToString(InputStream ios) {
// TODO Auto-generated method stub
StringWriter writer = new StringWriter();
try {
IOUtils.copy(ios, writer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String theString = writer.toString();
//String content = FileUtils.readFileToString(ios);
return theString;
}
}
Help.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/index1"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/a" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/menu"
android:textColor="@color/white" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/b" />
</RelativeLayout>
<TextView
android:id="@+id/textViewhelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@raw/help" />
</LinearLayout>
No comments:
Post a Comment