2016-06-26 3 views
0

現在、私はAndroidアプリをコードすることを学んでおり、「The Big Nerd Ranch Guide」を持っています。私はCriminalIntentアプリを終了したようアクティビティが起動せず、RecyclerViewが空です。

は私がCriminalIntentとかなり類似している別のアプリケーションを構築し始めました。 (私はちょうど私が学んだことを練習したい)

アプリはプロジェクト管理ツールのいくつかの並べ替えを説明する必要があります。

次の問題:何も動作しません!

アプリを起動すると、空白の画面が表示されます。プロジェクト全体のブレークポイントは捕らえられていません。

起動アクティビティは、RecyclerViewを含むFragmentを含むアクティビティでなければなりません。

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:(起動する必要があります)

public class ProjectListActivity extends SingleFragmentActivity { 

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

<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> 

に他の活動の両方を継承する抽象クラスがあります:

blank screen

はここでマニフェストのコードです

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()); 
    } 
} 
} 

申し訳ありませんが、私は馬鹿だ場合。 :(私はそれをデバッグすることはできません

は、あなたが私を助けることを願って

EDIT

XML-ファイル

:。。

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.ndraeger.android.projecttrackstar.ProjectActivity"> 

<include layout="@layout/activity_fragment_content"/> 

activity_fragment.xml

activity_fragment_content.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/fragment_container" 
android:layout_width="match_parent" 
android:layout_height="match_parent"/> 

fragment_project_list.xml:

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
            android:id="@+id/project_recycler_view" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent" /> 

list_item_project。XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
<CheckBox 
    android:id="@+id/list_item_finished_check_box" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:padding="4dp"/> 
<TextView 
    android:id="@+id/list_item_title_text_View" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@id/list_item_finished_check_box" 
    tools:text="Project Title"/> 
<TextView 
    android:id="@+id/list_item_description_text_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/list_item_title_text_View" 
    android:layout_toLeftOf="@id/list_item_finished_check_box" 
    tools:text="Project Description"/> 
<TextView 
    android:id="@+id/list_item_date_text_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/list_item_description_text_view" 
    android:layout_toLeftOf="@id/list_item_finished_check_box" 
    tools:text="Project Date"/> 

(終了タグがカットオフ;申し訳ありませんが、任意のより良いそれをフォーマットすることができませんでした)あなたの活動で

+0

[mcve]をデバッグできるようにしてください。コードが進んでいると思われる場所で印刷するための 'Log.d'文を追加してください –

+0

ありがとう!私はそれを試みます。 –

+0

いずれにしても、表示された内容は大丈夫ですが、ProjectListActivityから 'onCreate'を明示的に実装してレイアウトが正しく画面に表示され、' projectLab.getProjects() 'が空リストでないことを確認することができます。また、ツールバーを追加して空の画面を表示しないようにしてください。 –

答えて

3

  @Override 
      protected void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
     } 

ない

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

    } 
を試してみてください
+0

感謝!誤って間違ったものを選択したことがあります。ただ好奇心が強い:PersitableBundleは何ですか? –

+0

クラスは、安全に永続化してディスクから復元できる単純なオブジェクトに限定されています。 [詳しい説明](https://developer.android.com/reference/android/os/PersistableBundle.html) –

+0

ありがとうございました。 –

関連する問題