我在导航菜单itemClick中使用了它,但它显示上面的错误。我该怎么做才能删除它?
if (id == R.id.item_alarm){
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(R.id.fragment_container, new NotificationActivity()).commit();
/*Wrong 2nd argument type. Found: 'com.sagar.kugeclass.NotificationActivity', required: 'android.support.v4.app.Fragment'
这是我想在单击导航抽屉菜单项时显示的NotificationActivity:
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.sagar.adapters.RecyclerAdapter;
import com.sagar.models.CardItemModel;
import java.util.ArrayList;
import java.util.List;
/**
* A simple {@link Fragment} subclass.
*/
public class NotificationActivity extends AppCompatActivity implements View.OnClickListener {
private Button alarmButton;
private Context context;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notification_activity_layout);
alarmButton = (Button) findViewById(R.id.alarmButton);
alarmButton.setOnClickListener(this);
}
@Override
public void onClick(View view){
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent repeating_intent = new Intent(context,Repeating_activity.class);
repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,100,repeating_intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.arrow_up_float)
.setContentTitle("Title")
.setContentText("Content")
.setAutoCancel(true);
notificationManager.notify(100,builder.build());
}
}
答案 0 :(得分:0)
您正在进行Fragment
交易,但正在替换为Activity
(NotificationActivity
)。如果您想首先使用片段,请为NotificationActivity
创建一个片段,并将此Activity
的代码转移到Fragment
。