현재 Android 앱을 코딩하는 법을 배우고 있습니다. "The Big Nerd Ranch Guide"입니다. 활동이 시작되지 않았습니다. RecyclerView가 비어 있습니다.
은 내가 CriminalIntent 꽤 유사하다 다른 응용 프로그램을 구축 시작 CriminalIntent 응용 프로그램을 종료한다. (방금 배운 것을 연습하고 싶습니다.)앱에서 일종의 프로젝트 관리 도구를 설명해야합니다.
다음 문제 : 아무것도 작동하지 않습니다!
앱을 실행하면 빈 화면이 표시됩니다. 전체 프로젝트의 중단 점은 잡히지 않습니다.
시작 활동은 RecyclerView가 포함 된 부분을 포함하는 활동이어야합니다.
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>
다른 활동을 모두 상속 추상 클래스가있다 :
여기 매니페스트 코드입니다
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());
}
}
}
미안 해요, 난 바보 야합니다. :(
나는 그것을 디버깅 할 수 없습니다
당신이 나를 도울 수 있기를 바랍니다편집
XML-파일 :..
activity_fragment.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_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"/>
(닫는 태그 차단, 죄송합니다, 더 좋은 포맷 없습니다) 활동에
디버깅 할 수있는 [mcve]를 만들어보십시오. 코드가 돌아가고 있다고 생각하는 곳에'Log.d' 문을 추가하십시오. –
감사합니다! 나는 그것을 시도 할 것이다. –
어쨌든 여러분이 보여준 것은 괜찮아 보이지만, ProjectListActivity에서'onCreate'를 명시 적으로 구현하고 레이아웃이 화면을 올바르게 채우고 있는지 확인하고'projectLab.getProjects()'가 빈 목록이 아닌지 확인하십시오 . 또한 툴바를 추가하여 빈 화면을 얻지 마십시오. –