2011-12-27 1 views
0

Heres는 안드로이드

 public void onClick(View view) { 
      Intent i = new Intent(First.this,second.class); 
      startActivity(i); 
      cat=(EditText) findViewById(R.id.textView_cat); 
      String s = getIntent().getStringExtra("myString"); 
      cat.setText(s); 

Heres는 내 첫 수업 내 두 번째 클래스에서 한 스크린에서 다른 스크린으로 값을 전달

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {    
      @SuppressWarnings("unchecked") 
      HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);     
     String selectedFromList = o.get("name");//(String) (lv.getItemAtPosition(position)); 
      Intent i = new Intent(second.this, First.class); 
      i.putExtra("myString", selectedFromList); 
      startActivity(i); 
    } 

내가의 버튼을 클릭 한 후 두 번째 클래스 (두 번째 화면)에 가고 싶다 처음 (첫 번째 화면에서). 그런 다음 첫 번째 (화면)에서 두 번째 클래스 (화면)에서 선택한 listitem의 값에 액세스하려고합니다. 하지만 그렇게하는 데 문제가 있습니다. 도와 주시면 감사하겠습니다 .. !!

first.class의 값을 second.class로 전달할 수 있지만 second.class에서 값을 가져 와서 first.class에서 액세스하려고합니다. !! Theres 문제 ... !!!

고맙습니다.

+0

오류 발생을 줄 수 있을까요? 내가 아는 한, 당신은 옳은 일을하는 것처럼 보입니다 : 클릭 된 아이템을 얻고, 당신이 끼어 들었던 데이터를 얻고, putExtra를 시작하고, 활동을 시작하십시오. 아마도 클래스 이름 지정에 문제가 있습니다. logcat의 의미는 무엇입니까? –

+0

정확히 어디 값에 액세스 하시겠습니까? – coder

+1

귀하의 경우 [Activity.startActivityForResult()] (http://developer.android.com/reference/android/app/Activity.html)를 사용하십시오. – yorkw

답변

0

두 가지 방법으로 변수를 전달할 수 있습니다. 여기

myIntent.putExtra(String name, Bundle value); 

가에 안드로이드 documentaton입니다 :

1) 의도의 추가 값을 사용합니다. http://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String, android.os.Bundle)

2)는 응용 프로그램 클래스를 사용합니다. http://developer.android.com/reference/android/app/Application.html 응용 프로그램 클래스는 모든 활동에 데이터를 사용할 수있게하는 데 사용할 수있는 단일 항목을 만듭니다. 활동은

activity.getApplication(); 

http://developer.android.com/reference/android/app/Activity.html#getApplication 통해 응용 프로그램을 참조()