0

I have a main Activity and it has two fragments, ListFramgment and DetailFragment. In ListFragment, on the event of selecting a choice, I am making a query to database which will return an array. I am passing this array to DetailFragment.

public void onListItemClick(ListView l, View v, int position, long id) {
    String selectedStore = (String) getListAdapter().getItem(position);
    DetailFragment fragment = (DetailFragment) getFragmentManager()
            .findFragmentById(R.id.detailFragment);
    if (fragment != null && fragment.isInLayout()) {
        TestAdapter mDbHelper = new TestAdapter(getActivity());
        mDbHelper.createDatabase();
        mDbHelper.open();

        Cursor curItemList = mDbHelper.getItemList(selectedStore);
        String[] itemList = new String[curItemList.getCount()];
        int i = 0;
        while(curItemList.moveToNext()){
            String item = curItemList.getString(0);
            itemList[i] = item;
            i++;
        }


        mDbHelper.close();

        fragment.setText(itemList);

        //getItemList(selectedStore);



    }

Here is DetailFragment code:

    public class DetailFragment extends android.app.ListFragment {

//   String qty;
//   String pr;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("Test", "hello");
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.details, container, false);
        return view;
    }

    public void setText(final String[] itemList) {
        ListView view = (ListView) getView().findViewById(R.id.detailsText);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_1, itemList);
        view.setAdapter(adapter);
}

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        Toast.makeText(null, "time for popup", Toast.LENGTH_SHORT).show();
    }

As the application starts, it is crashing and the LogCat is:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.click4tab.fragmentvogella/com.click4tab.fragmentvogella.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
4

2 回答 2

1
Binary XML file line #14: Error inflating class fragment

检查你Layout xml file有什么错误line no.14

于 2012-08-07T12:10:25.313 回答
0

就我而言,解决方案是写

super.onCreateView(inflater, container, savedInstanceState);

在我的 onCreateView 实现中。

于 2013-03-08T13:57:34.020 回答