mardi 28 juin 2016

Activity not launching, RecyclerView is empty

I'm currently learning to code Android apps and got myself "The Big Nerd Ranch Guide".

As I finished the CriminalIntent app I started building another app which is pretty similar to CriminalIntent. (I just want to practise the things i learned)

The app should describe some sort of project management tool.

Following problem: Nothing works!

When I launch the app I get a blank screen. Breakpoints throughout the whole project aren't being caught.

The launching Activity should be the one including the Fragment that includes the RecyclerView.

blank screen

Here's the Manifest code:

<activity android:name=".ProjectListActivity">
     <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER"/>
     </intent-filter>
</activity>
<activity
      android:name=".ProjectActivity"
      android:label="@string/app_name"
      android:theme="@style/AppTheme.NoActionBar">
</activity>

There's the abstract class that inherits to both other Activities:

public abstract class SingleFragmentActivity extends FragmentActivity{

 protected abstract Fragment createFragment();

 @Override
 public void onCreate(Bundle savedInstanceState, PersistableBundle  persistentState) {
    super.onCreate(savedInstanceState, persistentState);
    setContentView(R.layout.activity_fragment_content);

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }
 }
}

ProjectListActivity: (should be launched)

public class ProjectListActivity extends SingleFragmentActivity {

 @Override
 protected Fragment createFragment() {
     return new ProjectListFragment();
 }
}

ProjectListFragment:

public class ProjectListFragment extends Fragment {

private RecyclerView mProjectRecyclerView;
private ProjectAdapter mAdapter;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_project_list, container, false);

    mProjectRecyclerView = (RecyclerView) v.findViewById(R.id.project_recycler_view);
    mProjectRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    updateUI();

    return v;
}

private void updateUI() {
    ProjectLab projectLab = ProjectLab.getInstance(getActivity());
    List<Project> projects = projectLab.getProjects();

    mAdapter = new ProjectAdapter(projects);
    mProjectRecyclerView.setAdapter(mAdapter);
}




private class ProjectAdapter extends RecyclerView.Adapter<ProjectHolder> {

    private List<Project> mProjects;

    public ProjectAdapter(List<Project> projects) {
        mProjects = projects;
    }

    @Override
    public ProjectHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
        View v = layoutInflater.inflate(R.layout.list_item_project, parent, false);

        return new ProjectHolder(v);
    }

    @Override
    public void onBindViewHolder(ProjectHolder holder, int position) {
        Project project = mProjects.get(position);
        holder.bindProject(project);
    }

    @Override
    public int getItemCount() {
        return mProjects.size();
    }
}




private class ProjectHolder extends RecyclerView.ViewHolder {

    private Project mProject;
    private TextView mTitleTextView;
    private TextView mDescriptionTextView;
    private TextView mDateTextView;
    private CheckBox mSolvedCheckBox;

    public ProjectHolder(View itemView) {
        super(itemView);

        mTitleTextView = (TextView)
                itemView.findViewById(R.id.list_item_title_text_View);

        mDescriptionTextView = (TextView)
                itemView.findViewById(R.id.list_item_description_text_view);

        mDateTextView = (TextView)
                itemView.findViewById(R.id.list_item_date_text_view);

        mSolvedCheckBox = (CheckBox)
                itemView.findViewById(R.id.list_item_finished_check_box);
    }

    public void bindProject(Project project) {
        mProject = project;
        mTitleTextView.setText(mProject.getTitle());
        mDescriptionTextView.setText(mProject.getDescription());
        mDateTextView.setText(new SimpleDateFormat("EEEE, dd.MM.yyyy").format(mProject.getDate()));
        mSolvedCheckBox.setChecked(mProject.isFinished());
    }
}
}

Sorry, if I'm dumb. :(

I cannot debug it.

Hope you can help me.

Aucun commentaire:

Enregistrer un commentaire