Ich weiß, dass es schon einige Fragen für dieses Problem gibt, da ich eine Stunde gesucht habe, aber keine von beiden hat mein Problem gelöst, noch ist die Lösung zu alt.Mehrere GridView im selben scrollbaren Layout/Fragment hinzufügen
Ich arbeite an einer Event-App und zeigt die Anwesenheit von Leuten an, die zu ihr gehen. Es muss zwei GridView haben: JA und NEIN, je nach Anwesenheit, und es zeigt das Bild der Gäste.
Ich habe bereits die "YES" GridView gemacht und habe versucht, eine neue TextView und GridView zu meinem Layout hinzufügen + bekommen das Layout davon in Java für meine "Nein" GridView , aber es zeigt nur die erste.
Was mache ich falsch? Ich verwende Fragmente für jeden meiner Tabs.
Dies ist, was ich vs. was ich will:
Dieses Layout mein Fragments ist:
[fragment_one.xml]
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.example.MainActivity.OneFragment">
<TextView android:id="@+id/title_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="14dp"
android:text="Yes"
android:textAllCaps="true"
android:textSize="14sp"
android:fontFamily="sans-serif-regular" />
<GridView android:id="@+id/gridview_yes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/title_yes"
android:numColumns="4"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:gravity="center" />
<TextView android:id="@+id/title_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="14dp"
android:text="No"
android:textAllCaps="true"
android:textSize="14sp"
android:fontFamily="sans-serif-regular" />
<GridView android:id="@+id/gridview_no"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/title_no"
android:numColumns="4"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:gravity="center" />
</LinearLayout>
Dies ist Java meines Fragment:
public class OneFragment extends Fragment {
public OneFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_one, container, false);
GridView gridViewYes = (GridView) view.findViewById(R.id.gridview_yes);
GridView gridViewNo = (GridView) view.findViewById(R.id.gridview_no);
gridViewYes.setAdapter(new ImageAdapter(view.getContext())); // uses the view to get the context instead of getActivity()
gridViewNo.setAdapter(new ImageAdapter(view.getContext())); // uses the view to get the context instead of getActivity()
gridViewYes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(getActivity(), "Esta es la imagen " + position + ".", Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
Verwendung mit einem Layout-Manager wie dies ein RecyclerView https://github.com/TonicArtos/SuperSLiM ist –