Hi I’m working on a help section for my application I plan to store the contents within a .txt file. I’m having some trouble when it comes to extracting the text and using set the text of a TextView. Does anyone have any ideas? Why is the text in the .txt document not being added to the text view.
I’m fairly new to this so sorry if it’s a Noob question.
Any help would be appreciated.
Thanks in advance.
Here's the code
package com.maths_wizard;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class InstructionActivity extends Activity implements OnClickListener{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.instruction);
InputStream iFile = getResources().openRawResource(R.raw.help);
try {
TextView helpText = (TextView)findViewById(R.id.TextViewHelpText);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
}
}
public String inputStreamToString(InputStream is) throws
IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = "";
while ((strLine = dataIO.readLine()) != null) {
sBuffer.append(strLine + "\n");
}
dataIO.close();
is.close();
return sBuffer.toString();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}