----이게 강의보고 붙여본 indoorlist.java 입니다.-------

AVD로 실행하면리스트뷰빼고 버튼같은것만 보이고..리스트뷰는 아예없는것처럼보입니다.

-----------------------------------

 

 

package com.lx5475.hobbyexplorer;

import java.util.ArrayList;

 


import android.app.Activity;

import android.graphics.Color;

import android.graphics.drawable.ColorDrawable;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.EditText;

import android.widget.ListView;

 

public class indoorlist extends Activity {

    /** Called when the activity is first created. */

 ListView listView;

 EditText editText;

 ArrayList<String> list;

 ArrayAdapter<String> adapter;

 @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.tab);

       

        //ListView 의 참조값 얻어오기

        listView = (ListView)findViewById(R.id.listView);

        editText = (EditText)findViewById(R.id.editText);

       

        //출력할 데이터(Model)

        list = new ArrayList<String>();

        list.add("김구라");

               

        //안드로이드에서 제공하는 기본적인 Adapter 객체 생성하기(카카오톡같은 특별한 리스트뷰는 만들어야 한다)*커스터마이징

        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);

        //simple_list_item_1는 textview를 담고 있는 xml형태이다.

       

        //listview 객체에 아답터 객체 연결하기

        listView.setAdapter(adapter);

        //리스트뷰의 경계선을 노란색으로

        listView.setDivider(new ColorDrawable(Color.YELLOW));

        //경계선의 굵기를 2px

        listView.setDividerHeight(2);

           

    }

 //버튼을 눌렀을때 호출되는 콜백 메소드

 public void insert(View v){

  //EditText에 입력한 문자열을 읽어온다.

  String str = editText.getText().toString();

  if(str==null || str.equals("")) return;

  //모델 객체에 데이터 추가하기

  list.add(str);

  //아답터에 모델이 바뀌었다고 알린다.

  adapter.notifyDataSetChanged();

  //editText초기호

  editText.setText("");
 }
}


 

 

-----이게 tab.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"

    >

 <LinearLayout

  android:layout_width="fill_parent"

  android:layout_height="wrap_content"

  android:orientation="horizontal">

 

  <EditText android:layout_width="0dp"

   android:layout_height="wrap_content"

   android:layout_weight="3"

   android:id="@+id/editText"/>

 

  <Button android:layout_width="0dp"

   android:layout_height="wrap_content"

   android:layout_weight="1"

   android:text="입력"

   android:onClick="insert"/>

 

 </LinearLayout>

   

    <ListView

     android:layout_width="fill_parent"

     android:layout_height="fill_parent"

     android:id="@+id/listView"

     />

   

</LinearLayout>


 

그리고 추가로 tab이동후 화면전환 용으로

tabdisplay1.java가 레이아웃 tab.xml을 가리키고있습니다.

 

 

package com.lx5475.hobbyexplorer;

import android.app.Activity;

import android.os.Bundle;

import android.util.Log;

 


public class tabdisplay1 extends Activity{

 


 @Override

 protected void onCreate(Bundle savedInstanceState) {

  // TODO Auto-generated method stub

  super.onCreate(savedInstanceState);
  Log.e("#Act1#", "onCreate()");
  //화면 구성하기

  setContentView(R.layout.tab);


 

 }

}