如何在回收器适配器中添加片段?

崔哲熙

问题是我想在回收器视图中添加片段每一行数据并尝试在 XML 中添加片段并在视图持有者中设置。但是发生错误,说重复 id 0x7f070075,标签 null,或父 id 0xffffffff 与 SomeFragment 的另一个片段。并尝试了第二种方法,即在视图中动态添加框架布局,并在每个框架布局中放置唯一 id 并动态添加片段。问题是找不到视图的错误

Caused by: java.lang.IllegalArgumentException: Binary XML file line #0: Duplicate id 0x7f070075, tag null, or parent id 0xffffffff with another fragment for com.example.my.samefragmenttest.TestFragment 

当尝试调试时,虽然工作正常,但不是运行时..我的问题是我想回收列表行中的一个片段。有任何想法吗??谢谢你..

抱歉迟到了,这是我的代码

public class MainActivity extends AppCompatActivity {
RecyclerViewPager mRecyclerView;
List<Person> peopleList = new ArrayList<Person>();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initialData();

    mRecyclerView = (RecyclerViewPager) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new 
LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false));
    mRecyclerView.hasFixedSize();
    final RecyclerAdapter recyclerAdapter = new 
RecyclerAdapter(this,peopleList,this.getSupportFragmentManager());
    mRecyclerView.setAdapter(recyclerAdapter);

 }
}






/**
 * Created by MY on 2018-03-11.
 */

public class RecyclerAdapter extends 
RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
List<Person> personList;
Context context;
FragmentManager fragmentManager;
int count=0;

public RecyclerAdapter(Context context, List<Person> peopleList, 
 FragmentManager supportFragmentManager) {
    this.personList = peopleList;
    this.context = context;
    this.fragmentManager = supportFragmentManager;
}


 @Override
 public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);

    // Inflate the custom layout
    View view = inflater.inflate(R.layout.row_item, parent, false);

    // Return a new holder instance
    ViewHolder viewHolder = new ViewHolder(view);
    return viewHolder;
 }

 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
    Person person = personList.get(position);

    // Set item views based on your views and data model
    holder.id.setText(String.valueOf(person.getId()));
    holder.testFragment = new TestFragment();
 }

 @Override
 public int getItemCount() {
    return personList.size();
 }

 public class ViewHolder extends RecyclerView.ViewHolder{

    TextView id;
    LinearLayout linearLayout;
    FrameLayout frameLayout;
    TestFragment testFragment;

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    public ViewHolder(View itemView) {
        super(itemView);
        id = (TextView)itemView.findViewById(R.id.txt_id);
        linearLayout = (LinearLayout)itemView.findViewById(R.id.linear);
        frameLayout = (FrameLayout)itemView.findViewById(R.id.test_frame);

        if(testFragment==null){

            fragmentManager.findFragmentByTag(TestFragment.TAG);
           // TestFragment.newInstance(fragmentManager);
        }
    }
 }
桑顿·伊苏鲁·尼拉吉

我认为您不能将片段用作回收站视图。

请参阅此处。参考

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Android:如何在回收站布局适配器中动态填充片段?

如何在Firebase回收器适配器中实现recyclerview ItemClickListener()?

如何在片段中调用RecyclerView适配器的方法

如何在片段中声明适配器?

回收器视图适配器中的选项菜单

如何在回收者视图适配器中获取上下文

如何获得回收适配器中可用产品总价的总和并传递给另一个片段?

如何在 dialogFragment 中的 viewPager 中的片段中填充适配器?

我如何从视图分页器适配器中获取当前可见的片段。

如何在适配器的底部工作表片段中设置TextView占位符

如何在片段中为我的列表视图实现适配器

如何从活动通知片段中的适配器?

如何从片段中的RecyclerView适配器启动活动

片段的ViewPager中的Listview适配器-如何获取活动

如何从 Kotlin 中的适配器调用片段的函数?

将值从回收站适配器传递到android中的片段

如何将数据从回收站适配器发送到片段 如何从Recyclerview适配器调用片段函数

如何从适配器调用片段

如何从适配器调用片段方法?

如何在 recyclerview 适配器上添加长点击监听器?

ViewPager +片段中的适配器=>拖拉

从ViewPager中的片段调用适配器

在片段中设置适配器

从适配器中的片段调用元素

Firebase在Android的适配器中添加侦听器

如何在我的适配器上添加EventListener?

如何在 OnSuccessListener 中的 recyclerview 适配器中传递侦听器

如何在 Android Prebid sdk 中为 OpenX、Critio 和 Rubicon 添加适配器

如何在Keycloak资源中添加用于授权的HTTP方法(不带适配器)