Note that there are some explanatory texts on larger screens.

plurals
  1. POcall fragment issue in button onclick
    primarykey
    data
    text
    <p>I create a fragment extend class to call layout as following </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/date_time_label" android:layout_centerVertical="true" android:layout_marginLeft="200dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="32dp" android:textStyle="bold" android:text="time_label" /&gt; &lt;TextView android:id="@+id/last_view_time" android:layout_toRightOf="@+id/date_time_label" android:layout_alignBaseline="@+id/date_time_label" android:layout_marginLeft="8dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="32dp" /&gt; &lt;/LinearLayout&gt; package com.appnetics; import java.text.SimpleDateFormat; import java.util.Date; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; /** * DateTime */ public class details extends Fragment { private static String getDateTimeString(Date time) { return new SimpleDateFormat("d MMM yyyy HH:mm:ss") .format(time); } private final String time = getDateTimeString(new Date()); /** @see android.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) */ @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle b) { View view = inflater.inflate( R.layout.details, container, false); //!!! this is important ((TextView) view.findViewById(R.id.last_view_time)) .setText(time); return view; } } </code></pre> <p>now to use it I create layout like this </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" &gt; &lt;Button android:id="@+id/btn_showdetails" android:layout_width="100dip" android:layout_height="wrap_content" android:layout_marginLeft="110dip" android:layout_marginTop="15dip" android:text="Show Details" /&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:id="@+id/my_parent_layout" &gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>on the click event of the button I say </p> <pre><code>setOnClickListener(new View.OnClickListener() { public void onClick(View v) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); details fragment = new details(); fragmentTransaction.add(R.id.my_parent_layout, fragment); fragmentTransaction.commit(); } }); </code></pre> <p>but it raise error <strong>The method getFragmentManager() is undefined for the type new View.OnClickListener(){}</strong></p> <p>any idea how to solve that </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload