I am trying to edit an android application, at the moment it works very well, but I have seen the need to expand its functions.
What I want is to add a new fragment to the application. The application already has its Drewer defined as follows:
I need to add 1 more, it could be a "Hello Word" what I want is to add one more option than what you already have.
Another doubt is that I do not know how to add A new Attribute to the R.java File to create the R.id and link it. Any way to do it from Android study? You can add it in many ways but the application closes when you place the new fragment, I need your help.
Update
Perform the process that you recommended to me, in effect R.java created the new attribute R.id.
Well you can see the new id being used but apparently when creating the new Fragment and linking it with the layout id the application gives an error and closes, the fragment created it from here.
[! [enter the description of the image here] [3]] [3]
A new fragment_blank.xml file is created
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/img_no"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceMedium" />
And the file BlankFragment.java
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.anylabs.new.R;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link BlankFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
*/
public class BlankFragment extends Fragment {
private OnFragmentInteractionListener mListener;
public BlankFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_blank, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
} '
But when pricing the botton in the application, it closes, which will be wrong?
Solution:
The Class Fragment was Incomplete, and that gave the error but the Rebuild solved everything, thanks for helping me until the next