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