Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] RecyclerView == null logo após ser instanciado -> coisa do capeta

Ele não está executando em outra thread e sim na própria thread de UI. Veja lá: runOnUiThread().

Mas esse trecho de código não é suficiente para identificar o problema, porque não sabemos quando onIRCConnected() está sendo chamado e qual sua relação com o ciclo de vida do FragmentChat. Você afirma que durante a execução de onIRCConnected() o FragmentChat já está sendo exibido e o onCreateView() foi chamado, mas será isso mesmo?

2015-09-22 12:15 GMT-03:00 Marcelo Alves <malves.info@gmail.com>:
mas vc esta executando isso em uma thread, que vai ocorrer em paralelo a thread do ciclo de vida do Android..

Em ter, 22 de set de 2015 às 10:43, Matheus Henrique da Silva <matheustargaryen@gmail.com> escreveu:
Vou postar a sequência do código para que vocês possam entender o demônio que ta acontecendo.
No meu ChatFragment há um método para setar o adapter que será chamado pela activity. Mas ao chamar, o recycler é null, mesmo depois de ter passado o onCreateView() onde tudo é instanciado.

//ACTIVITY
@Override
   
public void onIRCConnected() {
        runOnUiThread
(


               
new Runnable() {
                   
@Override
                   
public void run() {


                        mViewPager
.getAdapter().notifyDataSetChanged();
                       
// nesse momento, o ChatFragment já está sendo exibido e é chamado o onCreateView();


                        setChatFragmentConversation
(mService.getChannelConversation());


                   
}
               
}
       
);


 
public void setChatFragmentConversation(Conversation conversation){


       
try {
           
FragmentChat frag = (FragmentChat) ((MyPagerAdapter) mViewPager.getAdapter()).getItem(1);
            frag
.setConversationAdapter(mService.getChannelConversation());
       
}catch (ClassCastException e){


       
}
   
}


// FRAGMENT


@Override
   
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             
Bundle savedInstanceState) {


       
View v = inflater.inflate(R.layout.layout_fragment_chat, container, false);


        mEditText
= (EditText) v.findViewById(R.id.edittext_input);
        mRecyclerView
= (RecyclerView) v.findViewById(R.id.recyclerview);
        mImageView
= (ImageView) v.findViewById(R.id.imageview_sendbutton);


        mRecyclerView
.setLayoutManager(new LinearLayoutManager(getActivity()));


        mImageView
.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View view) {
                onSendButtonClicked
(mEditText.getText().toString());
           
}
       
});


       
return v;
   
}


 
public void setConversationAdapter(Conversation conversation) {


        mConversation
= conversation;

       
// NESSE MOMENTO, NESSE MALDITO DESGRAÇADO MORFÉTICO MOMENTO, MRECYCLERVIEW É NULL... PQ? COMO?
        mRecyclerView
.setAdapter(new ChatRecyclerAdapter(conversation));


   
}

Qualquer ajuda é bem vinda e pode me ajudar a não desistir do projeto por estar cansado da ingrata e muitas vezes paradoxalmente ilógica vida de programador.
Obrigado.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário