2010-08-08 4 views
1

나는 안드로이드에서 메뉴 컨트롤에 관한 아주 간단한 질문이 있습니다. 몇 가지 간단한 숫자 계산을 수행하고 대답을 출력하는 프로그램을 작성하고 있습니다. 내 질문은 버튼을 누르면 프로그램을 두 번째 화면으로 이동시키는 방법과 사용자가 원래 화면으로 돌아 가게 할 수있는 방법입니다. 다음은 간단한 예를안드로이드에 대한 매우 간단한 메뉴 질문

화면 1

"Add Numbers" 

Input 1st # ____  
Input 2nd # ____  
(Add) 

화면 2 개

The answer is "____" 

사용자 입력이 개 정수입니다. 추가를 누른 다음 프로그램이 응답을 표시하는 두 번째 화면으로 이동합니다. 사용자가 원하는 경우 처음 화면으로 돌아가서 다시 시작할 수 있습니다.

나는이 사실을 알고 있지만 너무 많은 자원으로 나는 무엇을 찾을 지 모른다. 리소스에 대한 답변이나 링크가 가장 도움이됩니다. 고맙습니다!

+1

어떤 언어/플랫폼? – jwsample

+1

어떤 플랫폼, 언어 및 기술을 사용하고 있습니까? 콘솔 입출력 및 C? Windows상의 .NET WPF? –

답변

3

화면에 다음과 같은 레이아웃을 사용하여 숫자를 입력 할 수 있습니다. first.xml 파일의 이름을 지정하십시오.

<TextView 
     android:id="@+id/firstnumber" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Input Ist:" 
     android:textSize="20px" 
     android:textStyle="bold" 
     /> 

<EditText 
     android:id="@+id/first" 
     android:layout_height="wrap_content" 
     android:layout_width="250px" 

    /> 

    <TextView 
     android:id="@+id/secondnumber" 
     android:text = "Input 2nd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="20px" 
     android:textStyle="bold" 
     />  

    <EditText 
       android:id="@+id/second" 
        android:layout_height="wrap_content" 
        android:layout_width="250px" 

     /> 

    <Button 
      android:id="@+id/add_button" 
       android:text="Add" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="15px" 
       android:layout_centerHorizontal="true" 

       /> 

</LinearLayout> 

는이 숫자

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.first); 
     Button add = (Button) findViewById(R.id.add); 
     add.setOnClickListener(this); 
     EditText num1 = (EditText)findViewById(R.id.first); 
     EditText num2 = (EditText)findViewById(R.id.second); 
} 

Result.java 클래스의 클릭 리스너 코드

public void onClick(View v) { 

       int n1 = Integer.parseInt(num1.getText().toString()); 
       int n2 = Integer.parseInt(num2.getText().toString()); 
       int result = n1 + n2; 
       String res = Integer.toString(result); 
           Intent intent = new Intent(getApplicationContext(), Result.class); 
           intent.putExtra("result", result); //Passing the result to the second activity using intent 
       startActivity(intent); 
       } 

을 추가합니다. 이 도움이

public class Result extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.result); 
      Intent intent = getIntent(); 
       String result = intent.getStringExtra("result"); 
       TextView t1 = (TextView)findViewById(R.id.result); 
       t1.setText(result); 
    } 
} 

희망 ..

+0

가장 확실합니다. 당신은 제가 필요로하는 것을 직접적으로 보여주었습니다. 이 출발점은 나를 아주 크게 도와줍니다. 고마워요! – canyon289

1

사용중인 언어의 유형을 알 수 있습니까? 나는 최근 C#으로 그 일을했다. 프로그램을 시작하면 몇 가지 전원 옵션을 사용하여 자동으로 두 번째 화면으로 강제 이동됩니다.

그러나 만약 당신이 프로그램을 diff 화면으로 옮기고 있다면, C#에서는 쉽게 될 것입니다.

Screen Srn = Screen.PrimaryScreen; // gives your information of Primary Screen. 

Screen[] Srn = Screen.AllScreens; //gives u an array of all your available screen(srn[0] is primary screen, etc) 

그래서, IDE에서 인텔리을 사용하여, src.width 또는 src.bounds.width 같은 너비, 높이 등 캔트 정확히 기억하지만, 뭔가를 얻을 수 있어야합니다.

가장 쉬운 방법은 프로그램 x 축을 해당 화면으로 옮기는 것입니다.

0

ViewFlipper 클래스를 살펴보십시오. 그것은 탭처럼 작동하지만, 탭 UI는 없습니다. xml 레이아웃을 사용하여 2 개 이상의 화면을 표시하고 showNext() 또는 showPrevious()을 사용하여 화면을 넘길 수 있습니다.

+0

링크 주셔서 대단히 감사합니다!이제는 설명서를 읽었으며 완전히 이해하기 위해 다시 읽게 될 것입니다. – canyon289

1

ViewFlipper가 정상적으로 작동합니다. 또한 "startActivityForResult"를 시도하여 다음 화면으로 답변을 전달할 수 있습니다.