374
No
class MainActivity
package com.example.choi.mystudy25_2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.InputStream;
public class MainActivity extends AppCompatActivity {
final static String TAG="MainActivity";
Button btnIn;
TextView tvIn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnIn=(Button)findViewById(R.id.bt_in);
tvIn=(TextView)findViewById(R.id.tv_in);
btnIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputStream is =null;
try{
is=getResources().openRawResource(R.raw.reex);
byte[] data=new byte[is.available()];
while (is.read(data)!=-1){
}
tvIn.setText(new String(data));
}catch (Exception e){
e.printStackTrace();
}finally {
try {
if(is!=null)is.close();
}catch (Exception e2){
e2.printStackTrace();
}
}
}
});
}
}
R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
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="com.example.choi.mystudy25_2.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/tv_in"
android:textStyle="normal|bold"
android:textAlignment="textStart"
android:textSize="14sp" />
<Button
android:text="data in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt_in"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
댓글 ( 4)
댓글 남기기