Reputation: 1532
I have a fragment and I am inflating it like below, but it is giving runtime error:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View jobsView = inflater.inflate(R.layout.fragment_job_information, container, false);
textView = (TextView) jobsView.findViewById(R.id.textView);
if (jobInfo == null) {
EmployerHistory jobsQuery=new EmployerHistory();
jobInfo = jobsQuery.getJobInfo(employerName, position);
}
textView.setText(jobInfo.get("jobName").toString());
return jobsView;
}
Its corresponding layout is:
<fragment 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:id="@+id/jobInfoFragment">
<RelativeLayout 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"
tools:context="com.example.ankit.job_depot.employer.view.JobInformation">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</fragment>
Actually I am already on a fragment with listview and when user clicks on an element of listview that fragment needs to get changed by a new fragment, in my new fragment I have: l
istViewJobHistory.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
JobInformation newFragment = new JobInformation();
android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.listViewJobHistory, newFragment);
transaction.addToBackStack(null);
transaction.commit();
}
});
I am getting the following exception:
07-28 18:49:39.681 14474-14474/com.example.ankit.job_depot E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.ankit.job_depot, PID: 14474 android.view.InflateException: Binary XML file line #1: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at com.example.ankit.job_depot.employer.view.JobInformation.onCreateView(JobInformation.java:45) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
Upvotes: 0
Views: 579
Reputation: 2393
I think your main Activity should extend FragmentActivity
import android.support.v4.app.FragmentActivity;
Upvotes: 1