I am trying to make multi-columned listview and place it within fragment. I have spent much time in this, but didn't come up with any working solution. Error: Binary XML file line #40: Error inflating class fragment at android.app.Activity... In a need of working solution.. I am new here. activity_home.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.project.ecms.Home" >
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/navigation_drawer"
android:name="com.project.ecms.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" />
<fragment
android:id="@+id/bill_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.project.ecms.BillFragment"/>
fragment_billing_history.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/billing_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/months" >
</ListView>
<ListView
android:id="@+id/billing_list_heading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light">
</ListView>
</LinearLayout>
Rows for ListView row_bill.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/month"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/units"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:layout_weight="1"
android:text="" />
</LinearLayout>
BillFragment class in which I am making multi-columned listview
public class BillFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
ListView list_bill, list_heading;
ArrayList<HashMap<String, String>> mylist, mylist_title;
ListAdapter adapter_title, adapter;
HashMap<String, String> map_heading, map_list;
String[] status = { "Paid", "Not Paid", "Paid", "Not Paid"," Paid", "Paid", "Not Paid", "Paid", "Not Paid", "Paid", "Not Paid", "Paid" };
int[] units = {201, 321, 254, 113, 125, 56, 321, 418, 357, 465, 285, 963};
int[] amount = {2051, 5914, 5468, 3215, 5648, 8794, 3216, 6213, 4195, 1597, 743, 5739};
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.fragment_billing_history, container, false);
list_bill = (ListView) view.findViewById(R.id.billing_list);
list_heading = (ListView) view.findViewById(R.id.billing_list_heading);
PopulateList();
return view;
}
public void PopulateList(){
mylist = new ArrayList<HashMap<String, String>>();
mylist_title = new ArrayList<HashMap<String, String>>();
map_heading = new HashMap<String, String>();
map_heading.put("month", "Month");
map_heading.put("units", "Unit");
map_heading.put("amount", "Amount");
map_heading.put("status", "Status");
mylist_title.add(map_heading);
adapter_title = new SimpleAdapter(getActivity(),
mylist_title,
R.layout.row_bill,
new String[] {"month", "units", "amount", "status"},
new int[]{R.id.month, R.id.units, R.id.amount, R.id.status});
list_heading.setAdapter(adapter_title);
for (int i = 0; i < 12; i++) {
map_list = new HashMap<String, String>();
map_list.put("month", getResources().getStringArray(R.array.countries)[i]);
map_list.put("units", String.valueOf(units[i]));
map_list.put("amount", String.valueOf(amount[i]));
map_list.put("status", status[i]);
mylist.add(map_list);
}
adapter = new SimpleAdapter(getActivity(),
mylist,
R.layout.row_bill,
new String[] {"month", "units", "amount", "status"},
new int[]{R.id.month, R.id.units, R.id.amount, R.id.status});
list_bill.setAdapter(adapter);
}
}
And the Home activity in which
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager()
.findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
/*if(position==1)
fragmentManager
.beginTransaction()
.replace(R.layout.fragment_detail, Fragment.instantiate(getApplicationContext(), "com.project.ecms.BillFragment"))
.commit();
else*/
fragmentManager
.beginTransaction()
.replace(R.id.container,
PlaceholderFragment.newInstance(position)).commit();
}
No comments:
Post a Comment