Ich code grade für einen Anbieter und zwar kostenlos, sobal alles klappt biete ich es für andere Betreiber verschiedene Pakete an.
Ich arbeite sehr gerne mit ListView. Aber da ich einen Chat haben möchte, habe ich ein Youtube Video von einer Professorin angesehen. Leider wurde mir nixs angezeigt. Nach dem ich alle 3 Klassen über Chat GPT drüber geschauen habe, wurde mir 1 Nachricht angezeigt von 30!
Ich weiß grade nicht weiter, da ich das noch nie gebraucht habe, habe ich es nicht gelernt. Bei der Professorin hats geklappt...
Ich weiß nicht wie lange der Log in Android sein kann, evtl. weil das anzeigt, am Ende? : ,{"id":1448,"client":1,"rang":"default","mcname":"A
ohne das es abschließt? Ich importiere die letzten 30 Nachrichten
Ich bedanke mich für jede Hilfe!
Der Volley Response war Erfolgreich. Ein kleiner Auszug(Inhalt verändert jeden Datenschutz!):
Hier meine 4 Seiten:
Ich arbeite sehr gerne mit ListView. Aber da ich einen Chat haben möchte, habe ich ein Youtube Video von einer Professorin angesehen. Leider wurde mir nixs angezeigt. Nach dem ich alle 3 Klassen über Chat GPT drüber geschauen habe, wurde mir 1 Nachricht angezeigt von 30!
Ich weiß grade nicht weiter, da ich das noch nie gebraucht habe, habe ich es nicht gelernt. Bei der Professorin hats geklappt...
Ich weiß nicht wie lange der Log in Android sein kann, evtl. weil das anzeigt, am Ende? : ,{"id":1448,"client":1,"rang":"default","mcname":"A
ohne das es abschließt? Ich importiere die letzten 30 Nachrichten
Ich bedanke mich für jede Hilfe!
Der Volley Response war Erfolgreich. Ein kleiner Auszug(Inhalt verändert jeden Datenschutz!):
Code:
{"status":"success","data":[{"id":1468,"client":1,"rang":"kaiser","mcname":"Peter","nachricht":"HI","jahr":"2025","monat":"Mar","tag":"24","stunde":"18","min":"36","sekunde":"17","ban":0},{"id":1467,"client":1,"rang":"Java Forum","mcname":"LG","nachricht":"testen!","jahr":"2025","monat":"Mar","tag":"23","stunde":"17","min":"57","sekunde":"40","ban":0},
Hier meine 4 Seiten:
Java:
package com.andrealfredklug.....Steuerung;
import android.app.Fragment;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.andrealfredklug.....Adapter.GlobalChatAdapter;
import com.andrealfredklug.....Chat.GlobalChatKonstruktor;
import com.andrealfredklug.magicwolfmc.R;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexWrap;
import com.google.android.flexbox.FlexboxLayoutManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GlobalChat extends Fragment {
private List<GlobalChatKonstruktor> gloChat = new ArrayList<>();
String TAG = "GlobalChat";
RecyclerView recyclerView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View fragment_globalchat = inflater.inflate(R.layout.activity_global_chat, null);
return fragment_globalchat;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
MainExport();
recyclerView = (RecyclerView) view.findViewById(R.id.globalchat_recylerView);
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getActivity());
layoutManager.setFlexWrap(FlexWrap.WRAP);
layoutManager.setFlexDirection(FlexDirection.ROW);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new GlobalChatAdapter(getActivity(), gloChat));
}
private void MainExport() {
RequestQueue queue = Volley.newRequestQueue(getActivity());
StringRequest request = new StringRequest(Request.Method.POST, getResources().getString(R.string.mainExportGlobi_url), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String Response = response.trim();
Log.e(TAG, Response);
try {
JSONObject objekt = new JSONObject(Response);
if (objekt.getString("status").equals("Empty Key.")){
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View view2 = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getActivity().findViewById(R.id.layoutDialogContainer));
builder.setView(view2);
((TextView) view2.findViewById(R.id.textTitle)).setText("Key");
((TextView) view2.findViewById(R.id.textView_error)).setText("The key is empty.\n\n");
((Button) view2.findViewById(R.id.buttonAction)).setText("Okay");
((ImageView) view2.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final androidx.appcompat.app.AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
view2.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}else if (objekt.getString("status").equals("Wrong Key.")){
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View view2 = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getActivity().findViewById(R.id.layoutDialogContainer));
builder.setView(view2);
((TextView) view2.findViewById(R.id.textTitle)).setText("Key");
((TextView) view2.findViewById(R.id.textView_error)).setText("The key is wrong.\n\n");
((Button) view2.findViewById(R.id.buttonAction)).setText("Okay");
((ImageView) view2.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final androidx.appcompat.app.AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
view2.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
} else if (objekt.getString("status").equals("Error Database Connection.")){
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View view2 = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getActivity().findViewById(R.id.layoutDialogContainer));
builder.setView(view2);
((TextView) view2.findViewById(R.id.textTitle)).setText("Database");
((TextView) view2.findViewById(R.id.textView_error)).setText("Error Database Connection.\n\n");
((Button) view2.findViewById(R.id.buttonAction)).setText("Okay");
((ImageView) view2.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final androidx.appcompat.app.AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
view2.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}else if (objekt.getString("status").equals("empty")){
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View view2 = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getActivity().findViewById(R.id.layoutDialogContainer));
builder.setView(view2);
((TextView) view2.findViewById(R.id.textTitle)).setText("GlobalChat");
((TextView) view2.findViewById(R.id.textView_error)).setText("In the GlobalChat is don't a message.\n");
((Button) view2.findViewById(R.id.buttonAction)).setText("Okay");
((ImageView) view2.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final androidx.appcompat.app.AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
view2.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}else if (objekt.getString("status").equals("success")){
JSONArray dataArray = objekt.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i++) {
JSONObject dataObj = dataArray.getJSONObject(i);
GlobalChatKonstruktor chatMessage = new GlobalChatKonstruktor(
dataObj.getInt("client"),
dataObj.getString("mcname"),
dataObj.getString("rang"),
dataObj.getString("nachricht"),
dataObj.getString("tag"),
dataObj.getString("monat"),
dataObj.getString("jahr"),
dataObj.getString("stunde"),
dataObj.getString("min"),
dataObj.getString("sekunde")
);
gloChat.add(chatMessage);
}
recyclerView.getAdapter().notifyItemInserted(gloChat.size() - 1);
}
} catch (JSONException e) {
showErrorDialog("Parsing Error");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View view2 = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getActivity().findViewById(R.id.layoutDialogContainer));
builder.setView(view2);
((TextView) view2.findViewById(R.id.textTitle)).setText("VERROR");
((TextView) view2.findViewById(R.id.textView_error)).setText(error.toString());
((Button) view2.findViewById(R.id.buttonAction)).setText("Okay");
((ImageView) view2.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final androidx.appcompat.app.AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
view2.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}
}){
@Nullable
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> param = new HashMap<>();
param.put("minke", getResources().getString(R.string.main_expo_code));
return param;
}
};
queue.add(request);
}
private void showErrorDialog(String message) {
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getActivity().findViewById(R.id.layoutDialogContainer));
builder.setView(dialogView);
TextView title = dialogView.findViewById(R.id.textTitle);
TextView errorMessage = dialogView.findViewById(R.id.textView_error);
Button button = dialogView.findViewById(R.id.buttonAction);
ImageView icon = dialogView.findViewById(R.id.image_error);
title.setText("Error");
errorMessage.setText(message);
button.setText("Okay");
icon.setImageResource(R.drawable.ic_error);
final androidx.appcompat.app.AlertDialog dialog = builder.create();
dialog.setCancelable(false);
button.setOnClickListener(v -> dialog.dismiss());
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
dialog.show();
}
}
Java:
package com.andrealfredklug.....Chat;
public class GlobalChatKonstruktor {
private Integer client;
private String name;
private String rang;
private String message;
private String tag;
private String monat;
private String jahr;
private String stunde;
private String minute;
private String sekunde;
// Konstruktor
public GlobalChatKonstruktor(int client, String mcname, String rang, String nachricht,
String tag, String monat, String jahr,
String stunde, String min, String sekunde) {
this.client = client;
this.rang = rang;
this.name = mcname;
this.message = nachricht;
this.tag = tag;
this.monat = monat;
this.jahr = jahr;
this.stunde = stunde;
this.minute = min;
this.sekunde = sekunde;
}
//Sets
public void setClient(Integer client){
this.client = client;
}
public void setName(String name){
this.name = name;
}
public void setRang(String rang){
this.rang = rang;
}
public void setMessage(String message){
this.message = message;
}
public void setTag(String tag){
this.tag = tag;
}
public void setMonat(String monat){
this.monat = monat;
}
public void setJahr(String jahr){
this.jahr = jahr;
}
public void setStunde(String stunde){
this.stunde = stunde;
}
public void setMinute(String minute){
this.minute = minute;
}
public void setSekunde(String sekunde){
this.sekunde = sekunde;
}
//Get
public Integer getClient(){
return client;
}
public String getName(){
return name;
}
public String getRang(){
return rang;
}
public String getMessage(){
return message;
}
public String getTag(){
return tag;
}
public String getMonat(){
return monat;
}
public String getJahr(){
return jahr;
}
public String getStunde(){
return stunde;
}
public String getMinute(){
return minute;
}
public String getSekunde(){
return sekunde;
}
}
Java:
package com.andrealfredklug....Adapter;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.andrealfredklug.....Chat.GlobalChatKonstruktor;
import com.andrealfredklug.....R;
import java.util.List;
public class GlobalChatAdapter extends RecyclerView.Adapter<GlobalChatAdapter.GlobalChatHolder> {
private List<GlobalChatKonstruktor> chat;
private Context context;
//Konstruktor
public GlobalChatAdapter(Activity activity, List<GlobalChatKonstruktor> globalChat) {
this.chat = globalChat;
this.context = activity.getApplicationContext();
}
@Override
public int getItemCount() {
return chat.size();
}
public static class GlobalChatHolder extends RecyclerView.ViewHolder{
TextView client_holder_input;
TextView rang_holder_input;
TextView name_holder_input;
TextView message_holder_input;
TextView datum_holder_input;
public GlobalChatHolder(View itemView){
super(itemView);
client_holder_input = (TextView)itemView.findViewById(R.id.client_holder_input);
rang_holder_input = (TextView) itemView.findViewById(R.id.rang_holder_input);
name_holder_input = (TextView) itemView.findViewById(R.id.name_holder_input);
message_holder_input = (TextView) itemView.findViewById(R.id.message_holder_input);
datum_holder_input = (TextView) itemView.findViewById(R.id.datum_holder_input);
}
}
@NonNull
@Override
public GlobalChatHolder onCreateViewHolder(ViewGroup parent, int viewType){
View view = null;
if (viewType == 1) { // Minecraft Layout
view = LayoutInflater.from(context).inflate(R.layout.viewholder_globalchat_server, parent, false);
} else if (viewType == 2) { // Android Layout
view = LayoutInflater.from(context).inflate(R.layout.viewholder_globalchat_android, parent, false);
}
if (view == null) {
throw new IllegalStateException("Fehler: View konnte nicht erstellt werden!");
}
return new GlobalChatHolder(view);
}
@Override
public void onBindViewHolder(@NonNull GlobalChatHolder holder, int position) {
GlobalChatKonstruktor gchat = chat.get(position);
// Setze die Textwerte basierend auf den GlobalChat-Daten
if(gchat.getClient() == 1){
holder.client_holder_input.setText("Server");
}else if(gchat.getClient() == 2){
holder.client_holder_input.setText("Android");
}
holder.rang_holder_input.setText(gchat.getRang());
holder.name_holder_input.setText(gchat.getName());
holder.message_holder_input.setText(gchat.getMessage());
holder.datum_holder_input.setText(gchat.getTag() + " " + gchat.getMonat() + " " + gchat.getJahr() + " " + gchat.getStunde() + ":" + gchat.getMinute() + ":" + gchat.getSekunde());
}
@Override
public int getItemViewType(int position) {
GlobalChatKonstruktor gchat = chat.get(position);
if (gchat.getClient() == 1) {
return 1;
} else {
return 2;
}
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:background="@drawable/globalchat_server_style">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Server"
android:id="@+id/client_holder_input"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#297E2C"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Streamer"
android:id="@+id/rang_holder_input"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#EA9C2A"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/name_holder_input"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#673AB7"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/message_holder_input"
android:layout_marginLeft="10dp"
android:text="Ich bin neu hier auf dem Server und bräuchte eure Hilfe. Wie macht man hier ein Grundstück?"
android:textColor="#7E7C7C"
android:textSize="17sp"
android:textStyle="bold"
android:inputType="textMultiLine"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/datum_holder_input"
android:layout_marginLeft="10dp"
android:text="31. Dezember 2025 23:59:60"
android:textColor="#404040"
android:textSize="15sp"
android:textStyle="bold"
android:inputType="textMultiLine"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Steuerung.GlobalChat">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/global_sendEdit"
android:layout_marginBottom="40dp"
android:id="@+id/globalchat_recylerView"
/>
<EditText
android:id="@+id/global_sendEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="20dp"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:ems="14"
android:inputType="text"
android:background="@drawable/input_senden_style"
android:hint="Deine Nachricht ..." />
<ImageView
android:id="@+id/global_sendImage"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toRightOf="@id/global_sendEdit"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:src="@drawable/ic_send" />
</RelativeLayout>