Hello plusminus and everyone,
Myself is Dhr.
i m new in this Android World.
I made one application. The application is basically based on browsing a text file from eclipse.
In that I create a page which contains one button.
the user press this button and then after the text file which is in the eclipse is open and the user can read that file.
Here is my code:
browse.java
- Code: Select all
package abc.browsing_file;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class browse extends Activity {
private static final Object Button01 = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.Button01);
button.getId();
TextView helloTxt = (TextView)findViewById(R.id.hellotxt);
helloTxt.setText(readText());
}
public void myClickHandler(View v)
{
if(v.equals(((View) Button01).getId()))
{
readText();
}
}
private String readText()
{
InputStream inputStream = getResources().openRawResource(R.raw.hello);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try{
i= inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
}
catch(IOException e){
e.printStackTrace();
}
return byteArrayOutputStream.toString();
}
}
main.xml
- Code: Select all
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/hellotxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="22px"
/>
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="Browse" android:onClick="@string/buttonHandler">
</Button>
</LinearLayout>
strings.xml
- Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, browse!</string>
<string name="app_name">browsing_file</string>
<string name="buttonHandler"></string>
</resources>
hello.txt
- Code: Select all
hello..
welcome to Android Application.
Can anyone has knoeledge how ti solve it??
Please please .. Help mee..
Thanks/Regards,
Dhr