package com.android.test_kch3;

 

import java.util.ArrayList;

 

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class test_kch3 extends Activity {
    /** Called when the activity is first created. */
 public static final int INPUT = 0;
 public static final int STYLE = 1;
 public static final int ACT_OK = 2;
 
 ListView lv;
 ArrayAdapter<String> Adapter1;
 ArrayList<String> astr = new ArrayList<String>();
 String str1="";
 


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        lv = (ListView)findViewById(R.id.ListView01);
    
     Adapter1 = new ArrayAdapter<String>(this, android.R.layout.
          simple_list_item_1, astr);
       
     lv.setAdapter(Adapter1);
     
       
    }
   
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
     // TODO Auto-generated method stub
     
     menu.add(Menu.NONE, INPUT, Menu.NONE, "Input");
     menu.add(Menu.NONE, STYLE, Menu.NONE, "Style");
     return super.onCreateOptionsMenu(menu);
     
    }
   
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
     // TODO Auto-generated method stub
     
     switch(item.getItemId())
     {
     case INPUT:
      
      Intent i = new Intent();
   i.setClass(test_kch3.this, second.class);
   startActivityForResult(i, 1); 
   //startActivity(i);
      break;
      
     case STYLE:
     
      break;
     }
     
     return super.onOptionsItemSelected(item);
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
     //TODO Auto-generated method stub
     
     //Toast.makeText(test_kch3.this, "여기2", Toast.LENGTH_SHORT).show();
      if(resultCode==RESULT_OK)
      {
       //Toast.makeText(test_kch3.this, "여기2", Toast.LENGTH_SHORT).show();
       str1 = data.getStringExtra("intent_data");
       astr.add(str1);
       
       Toast.makeText(test_kch3.this, data.getStringExtra("intent_data") , Toast.LENGTH_SHORT).show();
       //astr.add(data.getStringExtra("intent_data"));
       //Adapter1.notifyDataSetChanged();
      
      
      }
      
      
      super.onActivityResult(requestCode, resultCode, data);
    }
}

마지막에 astr이라는 변수가 ArrayList<String> 인데요 str1은 "intent_data"라는 이름에 들어있는 스트링값을 넣어둔것이고요.

혹시나해서 두번째 java파일도 올릴께요.

add에서 계속 에러가 나네요 ㅠㅠ

그냥 add("스트링") 이런식으로 하니까 에러가 안나요....... 이거 원래 변수 넣으면 안되는건가요?

package com.android.test_kch3;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class second extends Activity
{
 EditText et;
 Button btn_ok;
 Button btn_cancel;
 String str="";
 Intent i;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.second);
  btn_ok = (Button)findViewById(R.id.BTN_OK);
  btn_cancel = (Button)findViewById(R.id.BTN_CANCEL);
  et = (EditText)findViewById(R.id.EditText01);
  
  btn_ok.setOnClickListener(mListener1);
  btn_cancel.setOnClickListener(mListener2);
  
  
  
 }
 
 OnClickListener mListener1 = new OnClickListener() {
  
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   //오케이버튼눌리면
   
   //str = str + et.getText().toString();

   i = getIntent();
   str = et.getText().toString();
   i.putExtra("intend_data", str);
   //Toast.makeText(second.this, str, Toast.LENGTH_SHORT).show();
   setResult(RESULT_OK, i);
   finish();
   //Toast.makeText(second.this, "여기1", Toast.LENGTH_SHORT).show();

  }
 };
 
 OnClickListener mListener2 = new OnClickListener() {
  
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   //캔슬버튼눌리면
   
  }
 };
 
 
 
 
}