I want to change my app ( extends Activity ) to Fragment ( extends SherlockFragment )
If I change it I have much errors;
public class AlarmClock extends SherlockFragment implements OnClickListener { This is my onCreateView:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // sanity check -- no database, no clock if (getContentResolver() == null) { new AlertDialog.Builder(this) .setTitle(getString(R.string.error)) .setMessage(getString(R.string.dberror)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }) .setOnCancelListener( new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { finish(); } }).setIcon(android.R.drawable.ic_dialog_alert) .create().show(); return; } View view = inflater.inflate(R.layout.alarm_clock, container, false); // menu buttons add = (ImageButton) findViewById(R.id.ibAdd); snooze = (ImageButton) findViewById(R.id.ibSnooze); add.setOnClickListener(this); snooze.setOnClickListener(this); mFactory = LayoutInflater.from(this); mPrefs = getSharedPreferences(PREFERENCES, 0); mCursor = Alarms.getAlarmsCursor(getContentResolver()); mAlarmsList = (ListView) findViewById(R.id.alarms_list); mAlarmsList.setAdapter(new AlarmTimeAdapter(this, mCursor)); mAlarmsList.setVerticalScrollBarEnabled(true); mAlarmsList.setItemsCanFocus(true); mClockLayout = (ViewGroup) findViewById(R.id.clock); mQuickAlarm = findViewById(R.id.ibSnooze); mQuickAlarm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showQuickAlarmDialog(); } }); setVolumeControlStream(android.media.AudioManager.STREAM_ALARM); setQuickAlarmVisibility(mPrefs.getBoolean(PREF_SHOW_QUICK_ALARM, true)); return view; } There are a lot of errors because there is no Activity. If is Activity it works.
I use "extends SherlockFragment" because I want to add it to the table. How fix this problem ? Please help me.