Add Recyclerview #1
@@ -17,9 +17,10 @@ import java.net.URISyntaxException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.janasroboter.REST.URL;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private final String URL = "http://192.168.4.1";
|
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private RecyclerView.Adapter modeAdapter;
|
private RecyclerView.Adapter modeAdapter;
|
||||||
private LinearLayoutManager layoutManager;
|
private LinearLayoutManager layoutManager;
|
||||||
@@ -57,7 +58,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void setRecyclerData(List<String> data) {
|
private void setRecyclerData(List<String> data) {
|
||||||
data.add("Mode 1");
|
data.add("Mode 1");
|
||||||
data.add("Mode 2");
|
for (int i = 2; i < 10; i++) {
|
||||||
|
data.add("Mode " + i);
|
||||||
|
}
|
||||||
|
data.add("Mode 1337");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -4,10 +4,12 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ModeListAdapter extends RecyclerView.Adapter<ModeListAdapter.LineHolder> {
|
public class ModeListAdapter extends RecyclerView.Adapter<ModeListAdapter.LineHolder> {
|
||||||
@@ -39,10 +41,32 @@ public class ModeListAdapter extends RecyclerView.Adapter<ModeListAdapter.LineHo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull LineHolder holder, final int position) {
|
public void onBindViewHolder(@NonNull LineHolder holder, final int position) {
|
||||||
// Set the username
|
// Set the mode text
|
||||||
String text = data.get(position);
|
String text = data.get(position);
|
||||||
System.out.println("Username: " + text);
|
System.out.println("Username: " + text);
|
||||||
holder.mode.setText(text);
|
holder.mode.setText(text);
|
||||||
|
|
||||||
|
// Set the click actions
|
||||||
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Thread t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String msg = "";
|
||||||
|
try {
|
||||||
|
// Aufruf mit Zahl an den Mikrocontroller senden
|
||||||
|
REST.getString(REST.URL + "/togglearg?state=" + (position + 1));
|
||||||
|
// Erfolgsnachricht anpassen
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
|
Toast.makeText(v.getContext(), "Setze auf Muster: " + (position + 1), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -17,6 +17,9 @@ public class REST {
|
|||||||
private static final MediaType MEDIA_TYPE_MP4 = MediaType.parse("video/mp4");
|
private static final MediaType MEDIA_TYPE_MP4 = MediaType.parse("video/mp4");
|
||||||
|
|
||||||
|
|
||||||
|
public static final String URL = "http://192.168.4.1";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a GET request to a url
|
* Make a GET request to a url
|
||||||
* @param url the url string
|
* @param url the url string
|
||||||
|
@@ -88,8 +88,8 @@
|
|||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerv"
|
android:id="@+id/recyclerv"
|
||||||
android:layout_width="409dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="540dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
Reference in New Issue
Block a user