我想将我的应用程序(扩展 Activity)更改为片段(扩展 SherlockFragment)
如果我改变它,我会有很多错误;
public class AlarmClock extends SherlockFragment implements OnClickListener {
这是我的 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;
}
有很多错误是因为没有Activity。如果是 Activity 它可以工作。
我使用“扩展 SherlockFragment”是因为我想将它添加到表中。 如何解决这个问题?请帮我。