Я сделал этоОшибка заменить фрагмент по Listfragment
@Override
public void onNavigationDrawerItemSelected(int position) {
Fragment obj = null;
ListFragment listfragment = null;
switch (position) {
case 0:
listfragment= new F1_fr();
break;
case 1:
obj= new F6_fr();
break;
case 2:
obj= new F3_fr();
break;
case 3:
obj= new F4_fr();
break;
case 4:
obj= new F5_fr();
break;
}
if (obj != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, obj)
.commit();
}
else if (listfragment != null) {
// do stuff if its a listfragment
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, listfragment)
.commit();
}
}
Но у меня есть ошибка здесь: .Привернуть (R.id.container, listfragment) , который сказал мне заменить android.supportv4.app.fragment в сделка фрагмента не может быть применена к (междунару, android.app.ListFragment)
public class F1_fr extends ListFragment {
View rootview;
TextView t;
ListView listView;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rootview=inflater.inflate(R.layout.f1_lay,container,false);
listView =(ListView) rootview.findViewById(R.id.list);
rootview.findViewById(R.id.semi_transparent).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), qr.class);
;
startActivity(intent);
}
});
return rootview;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final String[] items = getResources().getStringArray(R.array.heroes);
final ArrayAdapter<String> aa = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, items);
setListAdapter(aa);
}
}
У меня уже нет ошибки, спасибо, но теперь у меня есть эта ошибка, когда я пытаюсь открыть фрагмент, и он разбился «У вашего контента должен быть ListView, чей атрибут id« android.R.id.list ». – BtAndro
Это совершенно очевидно, не так ли? – laalto
Да, это немного пропустило список просмотров? – BtAndro