마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 스튜디오질문드립니다.

0 추천

아래에 있는 소스처럼 데이터를 입력하여 다른 화면에서 저장한 내용을 불러와 보일 수 있도록 코드를 짜보았습니다.

(오류 없는 상태이며 잘 돌아가는 소스입니다..) 

저는 여기서 데이터를 하나씩만 입력해도 저장 후 다음 화면에서도 저장된 갯수만큼 보여지고 싶습니다. 어떤 식으로 수정을 해야할까요?? 제발 도와주십시오!!

MainActivity.java

public class MainActivity extends AppCompatActivity {

    EditText an_Check_1, an_Check_2, an_Check_3, an_Check_4, an_Check_5;


    //public static final int READ_BLOCK_SIZE = 100;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        an_Check_1 = (EditText) findViewById(R.id.an_check_1);
        an_Check_2 = (EditText) findViewById(R.id.an_check_2);
        an_Check_3 = (EditText) findViewById(R.id.an_check_3);
        an_Check_4 = (EditText) findViewById(R.id.an_check_4);
        an_Check_5 = (EditText) findViewById(R.id.an_check_5);

    }

    public void save(View view){

        String an_Check1 = an_Check_1.getText().toString();
        String an_Check2 = an_Check_2.getText().toString();
        String an_Check3 = an_Check_3.getText().toString();
        String an_Check4 = an_Check_4.getText().toString();
        String an_Check5 = an_Check_5.getText().toString();

        File file = null;

        an_Check1 = an_Check1+" ";
        an_Check2 = an_Check2+" ";
        an_Check3 = an_Check3+" ";
        an_Check4 = an_Check4+" ";
        an_Check5 = an_Check5+" ";

        FileOutputStream fileOutputStream =  null;

        try {
            file = getFilesDir();
            fileOutputStream = openFileOutput("anda.txt", Context.MODE_PRIVATE);
            fileOutputStream.write(an_Check1.getBytes());
            fileOutputStream.write(an_Check2.getBytes());
            fileOutputStream.write(an_Check3.getBytes());
            fileOutputStream.write(an_Check4.getBytes());
            fileOutputStream.write(an_Check5.getBytes());

        } catch (IOException e) {
            e.printStackTrace();

        }
        finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        Toast.makeText(this, "Saved successfully", Toast.LENGTH_LONG).show();
    }

    public void next(View view){
        Toast.makeText(this, "Data page", Toast.LENGTH_LONG).show();
        Intent intent = new Intent(this, DBActivity.class);
        startActivity(intent);
    }

DBActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_db);
}

public void show(View view){

    Toast.makeText(this, "Data found", Toast.LENGTH_LONG).show();
}

public void back(View view){
    Toast.makeText(this, "Main Page", Toast.LENGTH_LONG).show();
    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
}
안듀 (200 포인트) 님이 2016년 9월 28일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...