0
Guys, I have a project that uses a Drawer navigation, so Mainactivity’s Mplements is already "busy", so many methods of doing this don’t work in my case. I have a mainactivity that controls the fragments I use. In one fragment I have an Edittext that will receive a name typed by the user and another that will receive this name and display it.
Fragment Editarnome
public class EditarNome extends Fragment implements View.OnClickListener{
private EditText editarNome;
private Button enviar;
String oi;
conexao con;
View rootview;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.fragment_editar, container, false);
editarNome = (EditText) rootview.getRootView().findViewById(R.id.editarNome);
oi = editarNome.getText().toString();
return rootview;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
con = (conexao) Inicio);
enviar = (Button) rootview.findViewById(R.id.enviar);
enviar.setOnClickListener(this);
}
@Override
public void onClick(View view) {
con.resposta(oi);
}
}
Fragment Inicio (is the Activity I used to manage the Start Fragment)
public class Inicio extends FragmentActivity implements conexao {
protected void onCreate(Bundle savedInstaceState) {
super.onCreate(savedInstaceState);
setContentView(R.layout.inicio);
}
@Override
public void resposta(String data) {
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
InicioFragment frag = (InicioFragment) manager.findFragmentById(R.id.fragment);
frag.changeText(data);
}
}
Fragment Homefragment (where I want to display the name)
public class InicioFragment extends Fragment {
TextView text;
View rootview;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.fragment_main, container, false);
return rootview;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
text = (TextView) rootview.findViewById(R.id.campoData2);
}
public void changeText(String data) {
text.setText(data);
}
}
Connected interface
connected public interface { public void reply(String data); }
The error that Android says is in Fragment Editarnome, when I call Activity Inicio. I hope you can help me! Vlw
Add the log with the error it generated
– Skywalker