Android fragments 碎片中的雅兰蒂斯搜索过滤器进入后台

Android fragments 碎片中的雅兰蒂斯搜索过滤器进入后台,android-fragments,android-recyclerview,searchfiltercollection,Android Fragments,Android Recyclerview,Searchfiltercollection,我正在使用android的雅兰蒂斯过滤器。我有一个片段而不是活动: `类激励:Fragment(),FilterListener{ private var incentiveList = ArrayList<Incentive>() var mAdapter: IncentiveListRecyclerAdapter? = null val handler: Handler by lazy { Handler() } private var mColors: IntArra

我正在使用android的雅兰蒂斯过滤器。我有一个片段而不是活动: `类激励:Fragment(),FilterListener{

private var incentiveList = ArrayList<Incentive>()
var mAdapter: IncentiveListRecyclerAdapter? = null
val handler: Handler  by lazy {
    Handler()
}
private var mColors: IntArray? = null
private var mTitles: Array<String>? = null
private var mAllQuestions: List<Incentive>? = null
private var mFilter: Filter<FilterTag>? = null
val that :Context? = null
var fragment : View? =null


override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    fragment = inflater!!.inflate(R.layout.activity_incentive_detail, container, false)
    return fragment
}

override fun onStart() {
    super.onStart()
    setIncentiveAdapter()

    mColors = getResources().getIntArray(R.array.colorslist);
    mTitles = getResources().getStringArray(R.array.job_titles);

    mFilter =  this.filter as Filter<FilterTag>

    mFilter!!.adapter =Adapter(getTags())
    mFilter!!.listener = this
    //the text to show when there's no selected items
    mFilter!!.noSelectedItemText = getString(R.string.str_all_selected)
    mFilter!!.build()

}

private fun getTags():List<FilterTag> {
    val tags = ArrayList<FilterTag>()
    for (i in 0..mTitles!!.size - 1) {
        tags.add(FilterTag(mTitles!![i], mColors!![i]))
    }
    return tags
}

fun setIncentiveAdapter(){
    //todo for salafi API call here and set adapter
    val in1  = Incentive("Get 100p by completing 10","Description","D","Cash","100","ACTIVE",10,"id-vcxsdt","ACTIVE",8,6,9)
    val in2  = Incentive("Get 100p by completing 10","Description","W","Cash","100","OPTED",10,"id-vcxsdt","OPTED",8,6,9)
    val in3  = Incentive("Get 100p by completing 10","Description","Y","Cash","100","EXPIRED",10,"id-vcxsdt","EXPIRED",8,6,9)
    val in4  = Incentive("Get 100p by completing 10","Description","Y","Cash","100","ACHIEVED",10,"id-vcxsdt","EXPIRED",8,6,9)
    val in5  = Incentive("Get 100p by completing 10","Description","Y","Cash","100","NOT_OPTED",10,"id-vcxsdt","NOT_OPTED",8,6,9)

    incentiveList.add(in1)
    incentiveList.add(in2)
    incentiveList.add(in3)
    incentiveList.add(in4)
    incentiveList.add(in5)

    mAdapter = IncentiveListRecyclerAdapter(context, incentiveList)
    incentiveListView.adapter = mAdapter
    incentiveListView.layoutManager = LinearLayoutManager(context)
}


private fun calculateDiff(oldList: List<Incentive>, newList: List<Incentive >) {
    DiffUtil.calculateDiff(object : DiffUtil.Callback() {
        override fun getOldListSize(): Int {
            return oldList.size
        }

        override fun getNewListSize(): Int {
            return newList.size
        }

        override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
            return oldList[oldItemPosition].equals(newList[newItemPosition])
        }

        override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
            return oldList[oldItemPosition].equals(newList[newItemPosition])
        }
    }).dispatchUpdatesTo(mAdapter)
}

override fun onFilterDeselected(item: FilterTag) {

}

override fun onFilterSelected(item: FilterTag) {
    Log.e("Item",item.getText())
    if (item.getText().equals(mTitles!![0])) {
        Log.e("mtitle",mTitles!![0])
        mFilter!!.deselectAll();
        mFilter!!.collapse();

    }
}

/*private fun findByTags(tags: List<FilterTag>): List<Incentive> {
    val questions = ArrayList<Incentive>()

    for (question in mAllQuestions!!) {
        for (tag in tags) {
            if (question.hasTag(tag.getText()) && !questions.contains(question)) {
                questions.add(question)
            }
        }
    }

    return questions
}*/

override fun onFiltersSelected(filters: java.util.ArrayList<FilterTag>) {
    Log.e("filter",filters.size.toString())
    /*val newQuestions = findByTags(filters)
    val oldQuestions = mAdapter.getQuestions()
    mAdapter.setQuestions(newQuestions)
    calculateDiff(oldQuestions, newQuestions)*/
}

override fun onNothingSelected() {
    if (this.incentiveListView != null) {
        mFilter!!.adapter =Adapter(getTags())
        incentiveListView.adapter = mAdapter
    }
} 

inner class Adapter(@NotNull items: List<FilterTag>) : FilterAdapter<FilterTag>(items) {
    override fun createView(position: Int, item: FilterTag): FilterItem {
        val filterItem = FilterItem(this@IncentiveActivity.activity)
        filterItem.strokeColor = mColors!![0]
        filterItem.textColor = mColors!![0]
        filterItem.cornerRadius = 14f
        filterItem.checkedTextColor = ContextCompat.getColor(this@IncentiveActivity.activity, android.R.color.white)
        filterItem.color = ContextCompat.getColor(this@IncentiveActivity.activity, R.color.m_color2)
        filterItem.checkedColor = mColors!![position]
        filterItem.text = item.getText()
        filterItem.deselect()


        return filterItem
    }


}
private var incentiveList=ArrayList()
var mAdapter:IncentiveListRecyclerAdapter?=null
val处理程序:由lazy执行的处理程序{
Handler()
}
私有变量mColors:IntArray?=null
私有变量mTitles:数组?=null
私人问题:列表?=null
私有变量mFilter:筛选器?=null
val:Context?=null
变量片段:视图?=null
覆盖创建视图(充气机:布局充气机?、容器:视图组?、savedInstanceState:捆绑?):视图{
碎片=充气机!!.充气(R.layout.activity\u激励\u细节,容器,错误)
返回片段
}
覆盖有趣的onStart(){
super.onStart()
setIncentiveAdapter()
mColors=getResources().getIntArray(R.array.colorslist);
mTitles=getResources().getStringArray(R.array.job_titles);
mFilter=this.filter作为过滤器
mFilter!!.adapter=适配器(getTags())
mFilter!!.listener=这个
//没有选定项目时要显示的文本
mFilter!!.noSelectedItemText=getString(R.string.str\u all\u selected)
mFilter!!.build()
}
private fun getTags():列表{
val tags=ArrayList()
用于(0..mTitles!!.size-1中的i){
添加(FilterTag(mTitles!![i],mColors!![i]))
}
返回标签
}
乐趣集激励适配器(){
//此处调用salafi API并设置适配器的todo
val in1=激励(“通过填写10”、“说明”、“D”、“现金”、“100”、“有效”、10、“id vcxsdt”、“有效”、8,6,9获得100便士)
val in2=激励(“通过填写10”、“说明”、“W”、“现金”、“100”、“选择”10、“id vcxsdt”、“选择”8,6,9获得100便士)
val in3=激励(“通过填写10”、“说明”、“Y”、“现金”、“100”、“过期”10、“id vcxsdt”、“过期”8,6,9获得100便士)
val in4=激励(“填写10获得100便士”,“说明”,“Y”,“现金”,“100”,“实现”,10,“id vcxsdt”,“过期”,8,6,9)
val in5=激励(“通过填写10”、“说明”、“Y”、“现金”、“100”、“未选择的”、10、“id vcxsdt”、“未选择的”、8,6,9获得100便士)
激励列表。添加(in1)
激励列表。添加(in2)
激励列表。添加(in3)
激励列表。添加(in4)
激励列表。添加(in5)
mAdapter=IncentiveListRecyclerAdapter(上下文,incentiveList)
incentiveListView.adapter=mAdapter
incentiveListView.layoutManager=LinearLayoutManager(上下文)
}
private fun calculateDiff(旧列表:列表,新列表:列表){
calculateDiff(对象:DiffUtil.Callback(){
重写getOldListSize():Int{
返回oldList.size
}
重写getNewListSize():Int{
返回newList.size
}
覆盖乐趣项相同(oldItemPosition:Int,newItemPosition:Int):布尔值{
返回oldList[oldItemPosition].equals(newList[newItemPosition])
}
覆盖相同的内容(oldItemPosition:Int,newItemPosition:Int):布尔值{
返回oldList[oldItemPosition].equals(newList[newItemPosition])
}
}).dispatchUpdatesTo(mAdapter)
}
覆盖已取消选择的过滤器(项目:过滤器标签){
}
覆盖选定的过滤器(项目:过滤器标签){
Log.e(“Item”,Item.getText())
if(item.getText().equals(mTitles!![0])){
Log.e(“mtitle”,mTitles!![0])
mFilter!!.DECALLE();
mFilter!!.collapse();
}
}
/*私人趣味findByTags(标签:列表):列表{
val questions=ArrayList()
for(问题中的问题!!){
用于(标记中的标记){
if(question.hasTag(tag.getText())&&!questions.contains(question)){
问题。添加(问题)
}
}
}
回答问题
}*/
覆盖已选择的筛选器(筛选器:java.util.ArrayList){
Log.e(“filter”,filters.size.toString())
/*val newQuestions=findByTags(过滤器)
val oldQuestions=mAdapter.getQuestions()
mAdapter.setQuestions(新问题)
calculateDiff(旧问题、新问题)*/
}
覆盖无选择的乐趣(){
if(this.incentiveListView!=null){
mFilter!!.adapter=适配器(getTags())
incentiveListView.adapter=mAdapter
}
} 
内部类适配器(@NotNull items:List):FilterAdapter(items){
覆盖视图(位置:Int,项目:FilterTag):FilterItem{
val filterItem=filterItem(this@IncentiveActivity.activity)
filterItem.strokeColor=mColors!![0]
filterItem.textColor=mColors!![0]
filterItem.cornerRadius=14f
filterItem.checkedTextColor=ContextCompat.getColor(this@IncentiveActivity.activity,android.R.color.white)
filterItem.color=ContextCompat.getColor(this@IncentiveActivity.activity,R.color.m_color2)
filterItem.checkedColor=mColors!![位置]
filterItem.text=item.getText()
filterItem.deselect()的
返回过滤器项
}
}
}` 我面临的问题是,当我展开过滤器时,它出现在我的列表的背景中,使我的列表保持可见


另外,如果我没有提供所有详细信息,并且我的问题不符合SOF条件,我也很抱歉。谢谢您

问题似乎在您的布局文件中。先生,你说得对。我发现问题出在框架布局上。非常感谢。