2013-04-13 2 views
-2

첫 번째 안드로이드 응용 프로그램을 작성 중이며 버튼을 클릭하면 새 화면에 결과를 표시하려고합니다. 내가 그것에 대해 검색, 나는 여러 활동이나 레이아웃이 필요하다는 것을 알게되었습니다. 그러나 나는 여전히 정확하게해야 할 일을 얻지 못했습니다 (이전에 Android를 사용하여 개발하지 않았습니다). 단추를 클릭 할 때 완전히 새로운 화면을 표시하려면 어떻게해야합니까?버튼을 클릭 할 때 새 화면을 표시하는 방법은 무엇입니까?

아무도 명확한 조치를 취할 수 있으면 좋겠다.

+0

'활동'을 전환하려면 '의도'를 사용하십시오. [이 링크]를 확인하십시오 [http://www.androidhive.info/2011/08/how-to-switch-between-activities-in-android/] – Sajmon

+0

예를 들어 링크를 줄 수 있습니까? http://developer.android.com/reference/android/content/Intent.html – Alaa

답변

0

Android Activity 클래스를 조사해야하는 것처럼 들립니다. 당신이 요구하는 많은 구현 중 하나는 애플리케이션의 각 화면에 Activity를 사용하는 것입니다.

이것은 새로운 활동을 시작하는 방법입니다 (here에서 가져옴).

/** Called when the user clicks the Send button */ 
public void sendMessage(View view) { 
    Intent intent = new Intent(this, DisplayMessageActivity.class); 
    EditText editText = (EditText) findViewById(R.id.edit_message); 
    String message = editText.getText().toString(); 
    intent.putExtra(EXTRA_MESSAGE, message); 
    startActivity(intent); 
} 
3

두 활동을 전환하려면 의도를 사용하십시오.

Intent inn1=getIntent(); 
inn1=new Intent(HomeActivity.this,SecondActivity.class); 
startActivity(inn1); 

먼저 안드로이드에서 간단한 작업을 만들고 main.xml에있는 버튼를 추가합니다. 그런 다음 findViewById 메소드를 사용하여 버튼의 ID를 찾으십시오. 그런 다음 OnClick 코드를 추가하고 Onclick 메서드 안에 의도 코드를 넣습니다. 그리고 매니 페스트 파일에 클래스 항목을 입력하는 것을 잊지 마십시오. 당신은 여전히 ​​어려움을 겪고있는 경우

1

그냥 만들 확실히 당신은 .XML 레이아웃

//Add the variable to avoid any errors 
Button goToAnotherClass; 

goToAnotherClass = (Button) findViewById(R.id.anotherclassbutton); //find the button by its assigned id 

//Make the button do something: 
goToAnotherClass.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent myIntent = new Intent(CurrentClass.this, 
        TheClassIWantToGoTo.class); 
      startActivity(myIntent); 

     } 
    }); 

시계 this 영상이 상관 관계.

관련 문제