Kullanıcı tarafından oluşturulan öğelerin listesini gösteren bir ListFragment
sahibim. "@android: id/list" olarak ayarlanmış bir ListView
ve "@android: id/empty" kimliğine sahip bir TextView
var.FragmentTransaction.replace() çalışmıyor
Kullanıcının listeye daha fazla girdi oluşturmasını sağlamak için bir parçayı görüntülemek için bir işlem çubuğu düğmesine sahibim. İşte onOptionsItemSelected()
yöntemdir şu şekildedir:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Fragment frag = null;
// Right now I only have code for the addCourse() fragment, will add more soon
switch (item.getItemId()) {
case R.id.addCourse:
frag = new AddCourseFragment();
break;
default:
return super.onOptionsItemSelected(item);
}
// The support library is being dumb and replace isn't actually
getFragmentManager().beginTransaction()
.remove(this).add(getId(), frag).addToBackStack(null).commit();
return true;
}
AddCourseFragment kodudur: Liste doldurulmamış olduğunda
Beklendiği gibipublic class AddCourseFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_addcourse, container, false);
// if (view.findViewById(R.id.timesFrame)!=null) {
Fragment timesFrag = new TimesFragment();
getChildFragmentManager().beginTransaction()
.add(R.id.timesFrame, timesFrag).commit();
// }
return view;
}
}
, android TextView
metni gösterir. Sonra kurs ekle düğmesine bastığımda bu olur:
Yeni metni olduğu kadar boş metni de gösterir.