- XML 디자인 파일
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent" >
       <TabHost
             android:id="@+id/tab_host"
             android:layout_width="fill_parent" 
             android:layout_height="fill_parent" > 
             <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_gravity="bottom"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
             <FrameLayout
                    android:id="@android:id/tabcontent" 
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
                    <!-- android:paddingTop="69px" -->
                    
                     
                    <LinearLayout
                           android:id="@+id/tab_view1"
                           android:orientation="vertical"
                           android:layout_width="fill_parent"
                           android:layout_height="fill_parent" >
                           <!-- 
                          <WebView
                            android:id="@+id/WebView01"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"/>
                            -->
                             
<LinearLayout
                           android:orientation="horizontal"
                           android:layout_width="fill_parent"
                           android:layout_height="fill_parent" >                            
                           <EditText
                            android:id="@+id/EditText01"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"/>
                           
                           <Button
                            android:id="@+id/Button01"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="입력"/>
                           
                           
                           <TextView
                            android:id="@+id/TextView01"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"/>
                        
                        
</LinearLayout>
                    </LinearLayout>    

                    <LinearLayout
                           android:id="@+id/tab_view2"
                           android:orientation="vertical"
                           android:layout_width="fill_parent"
                           android:layout_height="fill_parent" >
                           
                           <TextView
                            android:id="@+id/TextView02"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"/>
                    </LinearLayout>
                    <LinearLayout
                           android:id="@+id/tab_view3"
                           android:orientation="vertical"
                           android:layout_width="fill_parent"
                           android:layout_height="fill_parent" >
                           
                           <TextView
                            android:id="@+id/TextView03"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"/>
                    </LinearLayout>
             </FrameLayout>
       </TabHost>
</LinearLayout>

- 자바소스
public class AllNews extends Activity implements OnClickListener{
    @Override
public void onClick(View v) {
// TODO Auto-generated method stub
    String str_name = et.getText().toString();
    tv1.setText(str_name);
    //// 알림창을 띄움 : 시작 ////
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("알림창");
alert.setMessage("성명:" + str_name);
alert.setIcon(R.drawable.icon);
alert.setPositiveButton("확인", null);
alert.show();
}
/** Called when the activity is first created. */
    public void m1(){
    URL url = null;
   
        HttpURLConnection urlConnection = null;
        BufferedInputStream buf = null;
        
        try{
        //// URL 지정과 접속
        // 웹서버 URL 지정
        url = new URL("http://www.android.com/");
        // URL 접속
        urlConnection = (HttpURLConnection)url.openConnection();
       
        //// 웹문서 소스를 버퍼에 저장
        // 데이터 다운로드
        buf = new BufferedInputStream(urlConnection.getInputStream());
        // 데이터를 버퍼에 기록
        BufferedReader bufeader = new BufferedReader(new InputStreamReader(buf, "euc-kr"));
       
        String line = null;
        String page = "";
       
        // 버퍼의 웹문서 소스를 줄 단위로 읽어(line), page에 저장함.
        while((line = bufeader.readLine()) != null){
        page += line;
        }
       
        // page 내용을 화면에 출력
        tv1.setText(page);
        }catch(Exception e){
        tv1.setText(e.getMessage());
        }finally{
        //URL 연결해제
        urlConnection.disconnect();
        }
    }
    TextView tv1;
    WebView wv;
    Button bt;
    EditText et;
    LinearLayout layname;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TabHost tabHost = (TabHost)findViewById(R.id.tab_host);
        tv1 = (TextView)findViewById(R.id.TextView01);
        et = (EditText)findViewById(R.id.EditText01);
        bt = (Button)findViewById(R.id.Button01);
        layname = (LinearLayout)findViewById(R.id.tab_view1);
        
        
        TextView tv2 = (TextView)findViewById(R.id.TextView02);
        TextView tv3 = (TextView)findViewById(R.id.TextView03);
        tabHost.setup();
          
        // Tab1 Setting 
        TabSpec tabSpec1 = tabHost.newTabSpec("Tab1");
        tabSpec1.setIndicator("신문, 뉴스"); // Tab Subject
        tabSpec1.setContent(R.id.tab_view1); // Tab Content
        tv1.setText("신문, 뉴스 페이지 입니다.");      
        tabHost.addTab(tabSpec1);
        bt.setOnClickListener(this);
        
        // Tab2 Setting
        TabSpec tabSpec2 = tabHost.newTabSpec("Tab2");
        tabSpec2.setIndicator("포털, IT"); // Tab Subject
        tabSpec2.setContent(R.id.tab_view2); // Tab Content
        tv2.setText("포털, IT 페이지 입니다.");
        tabHost.addTab(tabSpec2);
        
        // Tab3 Setting
        TabSpec tabSpec3 = tabHost.newTabSpec("Tab3");
        tabSpec3.setIndicator("방송, 해외"); // Tab Subject
        tabSpec3.setContent(R.id.tab_view3); // Tab Content
        tv3.setText("방송, 해외 페이지 입니다.");
        tabHost.addTab(tabSpec3);
        
        // show First Tab Content
        tabHost.setCurrentTab(0);
    }
}

'스마트폰 > 안드로이드' 카테고리의 다른 글

데이터 바인딩2 공부  (0) 2011.05.13
데이터 바인딩1 공부  (0) 2011.05.13
anim2(애니메이션) 공부  (0) 2011.05.13
Activity Event 공부  (0) 2011.05.13
안드로이드 개발 개요.  (0) 2011.05.02

+ Recent posts