小编Ahm*_*zat的帖子

如何将数据从Recyclerview传递到Fragment

我有一个填充在Fragment中的recyclerView,我想启动一个新的Fragment并从适配器传递数据,我尝试使用Bundles但它总是给我的适配器类的空值

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> {
private LayoutInflater inflater;
private List<Information> mList;
private FragmentCommunication mCommunicator;

public RecyclerAdapter(Context context, List<Information> list,FragmentCommunication communication) {
    inflater = LayoutInflater.from(context);
    mList = list;
    mCommunicator=communication;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = inflater.inflate(R.layout.single_row, parent, false);
    MyViewHolder holder = new MyViewHolder(view,mCommunicator);
    return holder;
}

@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {

    final Information current = mList.get(position);
    holder.name.setText(current.name);
    holder.job.setText(current.job);

    FragmentB fragmentB=new FragmentB();
    Bundle bundle=new Bundle();
    bundle.putString("NAME",current.name);
    bundle.putString("JOB",current.job);
    fragmentB.setArguments(bundle);

} …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-recyclerview

5
推荐指数
2
解决办法
2万
查看次数

如何在单击主屏幕小部件时打开特定片段

如何在单击主屏幕小部件时打开特定片段,我已经可以打开一个Activity但我不知道如何从小部件打开片段这是我的小部件类

public class MyWidget extends AppWidgetProvider {
ComponentName watchWidget;
RemoteViews remoteViews;
private static final String SYNC_CLICKED = "automaticWidgetSyncButtonClick";

void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                     int appWidgetId) {



    remoteViews = new RemoteViews(context.getPackageName(), R.layout.My_widgets);
    watchWidget = new ComponentName(context, MyWidget.class);
    remoteViews.setTextViewText(R.id.appwidget_text,"Widget Example");
    // start Activity from the widget

    Intent configIntent = new Intent(context, MainActivity.class);
    PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.widget_container, configPendingIntent);
    appWidgetManager.updateAppWidget(watchWidget, remoteViews);
}
Run Code Online (Sandbox Code Playgroud)

那么任何想法?

android android-widget android-studio

1
推荐指数
1
解决办法
592
查看次数