我在我的应用程序中使用了RecyclerView支持,我看到了最奇怪的事情.在我触摸滚动之前,它不会显示任何项目.然后,突然之间,RecyclerView会自行填充.我已经确认填充了支持适配器的列表,并且在触摸事件之前永远不会调用onCreatViewHolder和onBindViewHolder.
以下是我设置recyclerview的方法:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
Drawable divider = new ColorDrawable(ProfileInfo.getCurrentProfileColor());
mInboxList.addItemDecoration(new DividerItemDecoration(getActivity(), divider, false));
mInboxList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
mInboxList.setAdapter(new InboxAdapter(getActivity(), new ArrayList<Conversation>()));
new AsyncTask<Void, Void, List<Conversation>{
public List<Conversation> doInBackground(...){
//load the conversations
return conversations;
}
public void onPostExecute(List<Conversation> conversations){
((InboxAdapter) mInboxList.getAdapter()).clear(false);
((InboxAdapter) mInboxList.getAdapter()).addAll(conversations);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Run Code Online (Sandbox Code Playgroud)
这是我的适配器的要点:
public class InboxAdapter extends RecyclerView.Adapter<InboxAdapter.ViewHolder> {
List<Conversation> mConversations; //initialized in contructor
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = mInflater.inflate(R.layout.inbox_item, parent, false);
ViewHolder holder …Run Code Online (Sandbox Code Playgroud) 我使用Recyclerview一个内部Fragment继MVP的谷歌的样品Android的架构,我试图让View部分被动地跟踪这篇文章中,这使得整个Recyclerview Adapter的数据模型和演示处理它的被动。
这是我的片段代码:
class OrderHistoryFragment : Fragment(), OrderHistoryContract.View {
lateinit var mPresenter: OrderHistoryContract.Presenter
lateinit var rvOrderHistory: RecyclerView
lateinit var orderHistoryAdapter : OrderHistoryAdapter
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val root = inflater!!.inflate(R.layout.order_history_fragment, container, false)
rvOrderHistory = root.findViewById<RecyclerView>(R.id.rvOrderHistory)
rvOrderHistory.layoutManager = LinearLayoutManager(context, LinearLayout.VERTICAL, false)
orderHistoryAdapter = OrderHistoryAdapter(mPresenter, object : HistoryItemListener {
override fun onReorder(orderHistory: OrderHistory) {
}
override fun onOpenOrder(orderHistory: OrderHistory) {
val orderIntent = Intent(activity, …Run Code Online (Sandbox Code Playgroud) mvp android kotlin android-recyclerview android-constraintlayout
I think I've read pretty much all the answers to all of the similar SO questions, and NONE of them seem to be working for me. It's driving me nuts, and I've spent too much time on this.
I'm implementing a RecyclerView here and I can't for the life of me update it's children. What happens is that after I update nothing changes on the screen, UNLESS I start scrolling. Once I scroll it updates perfectly.
This is my …
android android-recyclerview react-native recyclerview-layout react-native-android