Ich habe die activity_main.xml
mit einer FrameLayout
relativ zu einer ListViewFragment
. Ich möchte dies fragment
in diesem activity
zeigen. Aber es funktioniert nicht ListView
wird nicht angezeigt. Weißt du, wo das Problem ist?Listenansicht in der ListViewFragment wird nicht in der Aktivität
Haupttätigkeit xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_list"
/>
</android.support.constraint.ConstraintLayout>
Haupttätigkeit:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// here Im trying to add the fragment A to the activity but the listview is not appearing
getSupportFragmentManager().
beginTransaction().add(R.id.fragment_list,new ListViewFragment()).commit();
}
}
Listview xml:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
ListViewFragment:
public class ListViewFragment extends Fragment {
private ListView editor=null;
ArrayList<String> items = new ArrayList<>();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View result=inflater.inflate(R.layout.fragment_list, container, false);
editor=(ListView) (result.findViewById(R.id.listView));
ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, items);
editor.setAdapter(arrayAdapter);
return result;
}
}
Danke, aber die Listview erscheint auch nicht. – JonD
Aktualisierte Antwort. Überprüfen Sie es. – Anonymous