2011. 8. 24. 17:19

안드로이드의 Frame Layout과 Inner Class 방식으로 버튼 이벤트 처리하기


안드로이드의 Frame Layout = 자바의 Border Layout

package kr.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class OddEvenActivity extends Activity {
 private TextView text ;
 private Button btnOdd, btnEven ;
 
    /-* Called when the activity is first created. *-
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        text = (TextView)findViewById(R.id.text);
        btnOdd = (Button)findViewById(R.id.btnOdd);
        btnEven = (Button)findViewById(R.id.btnEven);
        
        btnOdd.setOnClickListener(new View.OnClickListener() {
   
          @Override
          public void onClick(View v) {
           // TODO Auto-generated method stub
           String oddNum = "" ;
    
           for(int i = 1 ; i < 10 ; i += 2) {
             oddNum += Integer.toString(i) ;
             oddNum += " " ;
           }
    
           text.setText(oddNum ) ;
         }
       }) ;
        
        btnEven.setOnClickListener(new View.OnClickListener() {
   
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            String evenNum = "" ;
    
            for(int i = 0 ; i <= 10 ; i += 2) {
              evenNum += Integer.toString(i) ;
              evenNum += " " ;
            }
    
           text.setText(evenNum ) ;
         }
       }) ;
        
    } 
    
} 

Trackback 0 Comment 0