원래 개발 하려는 화면은 여섯탭에 각 프래그먼트에 리스트 뷰 / 하단에 버튼 하나
이렇게 하고 싶은데 프래그먼트에 리스트뷰를 써본적이 없어서 에러가 나는데 질문 드립니다.
우선 리스트뷰는 가장 기본형으로 먼저 해보고 있습니다. 추후에 커스텀 리스트뷰를 쓸 계획입니다.
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
FragmentList frag = new FragmentList();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(R.id.fragment_container, frag);
transaction.addToBackStack(null);
transaction.commit();
}
}
public class FragmentList extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.fragment_list, container,false);
listView = (ListView)getActivity().findViewById(R.id.list);
String[] items = new String[]{"item1" , "item2", "item3"};
mAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1,items);
listView.setAdapter(mAdapter);
return view;
}
private ListView listView;
private ArrayList<String> item;
private ArrayAdapter<String> mAdapter;
}
메인 xml 입니다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.fragmentlistview.MainActivity" >
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"/>
</LinearLayout>
프래그먼트에 사용 할 레이아웃입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView
android:id="@+id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"></ListView>
<Button
android:id="@+id/more_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="more"/>
</LinearLayout>
Log 제일 첫 에러인데 무슨 의미인지 잘 모르겠습니다.
01-30 23:20:52.301: E/AndroidRuntime(1860): FATAL EXCEPTION: main
01-30 23:20:52.301: E/AndroidRuntime(1860): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragmentlistview/com.example.fragmentlistview.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
xml Fragment에 class를 지정해야 하나요 ??? 제가 나중엔 6개의 프래그먼트를 쓸건데
xml fragment 영역에 클래스를 지정하면 여러개를 어떻게 쓸수 있는지 궁금합니다... 가르침 부탁드립니다.