I have to xml.file
first :
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Text1" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:text="Button1" />
</RelativeLayout>
second :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_marginTop="28dp"
android:text="TextView" />
</RelativeLayout>
i have a txt.file in asset folder that its name is 12.txt i want when i press button1 in first xml.file i go to second xml.file and textview on it set with my txt.file in asset folder
code is :
public class Text2 extends Activity {
private TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.text2);
txt=(TextView)findViewById(R.id.textView1);
FileInputStream fis=null;
final StringBuffer buffer= new StringBuffer();
try {
fis = openFileInput("12.txt");
DataInputStream dataIO = new DataInputStream(fis);
String strLine = null;
if ((strLine = dataIO.readLine()) != null) {
buffer.append(strLine);
}
dataIO.close();
fis.close();
}
catch (Exception e) {
}
txt.setText(buffer.toString());
}
}
why it doesnt work ?? when i press button1 i go to second xml.file but textview is empty !!!