Moin,
Momentan komme ich nicht weiter. Meine custom ListView wird im Fragment richtig angezeigt, aber in einem AlertDialog nicht. Der Text im TextView wird nicht angezeigt.
Ich habe den Context von der Main auf den AlertDialog gesetze was leider auch nichts gebracht hat. Leider hat meine Internet recherche nichts ergeben. Ich hoffe jemand kann mir weiter helfen.
mfg
Nosti
Java: Aufruf AlertDialog
private void removeUser()
{
LayoutInflater li = LayoutInflater.from(this);
@SuppressLint("InflateParams") View view = li.inflate(R.layout.popup_removeuser, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setView(view);
ListView listeUser = view.findViewById(R.id.list_Player);
Button close = view.findViewById(R.id.button_Close);
TextView title = view.findViewById(R.id.removeuser_Title);
title.setBackground(getResources().getDrawable(R.drawable.gamerremove_pic));
final AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setCanceledOnTouchOutside(false);
Objects.requireNonNull(alertDialog.getWindow()).setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
listAdapter = null;
listAdapter = new ListAdapter(this, R.layout.listview_custom, namesList, 2);
listeUser.setAdapter(listAdapter);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
alertDialog.show();
}
Alles anzeigen
Java: Custom ListView Klasse
public class ListAdapter extends ArrayAdapter<String> {
private int layout;
private int mode;
private List<String> mObjects;
private Context context;
ListAdapter(Context context, int resource, List<String> objects, int mode) {
super(context, resource, objects);
mObjects = objects;
layout = resource;
this.mode = mode;
}
class ViewHolder {
TextView title;
Button button;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder mainViewholder = null;
if(convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(layout, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.title = convertView.findViewById(R.id.text_item);
viewHolder.button = convertView.findViewById(R.id.del_item);
convertView.setTag(viewHolder);
}
mainViewholder = (ViewHolder) convertView.getTag();
mainViewholder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (mode)
{
case 0:
removeListUser(position);
break;
case 1:
removeListTask(position);
break;
case 2:
removeListUserInGame(position);
break;
}
}
});
mainViewholder.title.setText(getItem(position));
return convertView;
}
}
Alles anzeigen
Java: XML custom ListView
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:padding="10dp"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/text_item"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/del_item"
android:gravity="center"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white"
android:textstyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/del_item"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/del_item"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@drawable/trash_pic"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Alles anzeigen
Java: XML AlertDialog
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/frame_border"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/removeuser_Title"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/gamerremove_pic"
android:textAlignment="center"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/list_Player"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.50"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ListView
android:id="@+id/list_Player"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_marginBottom="40dp"
android:scrollbars="vertical"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/removeuser_Title" />
<Button
android:id="@+id/button_Close"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/close_pic"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.50"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/list_Player"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Alles anzeigen