<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
class="com.oreilly.demo.android.contactviewer.DateTime"
android:id="@+id/date_time"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
}
public class DateTime extends Fragment {
private String time;
public void onCreate(Bundle state) {
super.onCreate(state);
if (null == time) {
time = new SimpleDateFormat("d MMM yyyy HH:mm:ss")
.format(new Date());
}
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle b) {
View view = inflater.inflate(
R.layout.date_time,
container,
false); //!!! this is important
((TextView) view.findViewById(R.id.last_view_time))
.setText(time);
return view;
}
}
Android 3.0 start support fragment
Google provide support package in previous veriosn
<supports-screens
android:smallScreens="false"
android:normalScreens="false"
android:largeScreens="true"
android:xlargeScreens="true" />