Add Recyclerview #1
@@ -27,4 +27,5 @@ dependencies {
|
|||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
||||||
|
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
package com.janasroboter;
|
package com.janasroboter;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -10,10 +14,16 @@ import android.widget.Toast;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private final String URL = "http://192.168.4.1";
|
private final String URL = "http://192.168.4.1";
|
||||||
|
private RecyclerView recyclerView;
|
||||||
|
private RecyclerView.Adapter modeAdapter;
|
||||||
|
private LinearLayoutManager layoutManager;
|
||||||
|
private List<String> data;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -29,6 +39,25 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
.detectNetwork()
|
.detectNetwork()
|
||||||
.penaltyLog()
|
.penaltyLog()
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
recyclerView = findViewById(R.id.recyclerv);
|
||||||
|
|
||||||
|
recyclerView.setHasFixedSize(true);
|
||||||
|
layoutManager = new LinearLayoutManager(getBaseContext());
|
||||||
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
data = new ArrayList<>();
|
||||||
|
setRecyclerData(data);
|
||||||
|
|
||||||
|
modeAdapter = new ModeListAdapter(data);
|
||||||
|
recyclerView.setAdapter(modeAdapter);
|
||||||
|
|
||||||
|
recyclerView.addItemDecoration(new DividerItemDecoration(getBaseContext(), DividerItemDecoration.VERTICAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRecyclerData(List<String> data) {
|
||||||
|
data.add("Mode 1");
|
||||||
|
data.add("Mode 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
53
app/src/main/java/com/janasroboter/ModeListAdapter.java
Normal file
53
app/src/main/java/com/janasroboter/ModeListAdapter.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package com.janasroboter;
|
||||||
|
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
public class ModeListAdapter extends RecyclerView.Adapter<ModeListAdapter.LineHolder> {
|
||||||
|
|
||||||
|
private List<String> data;
|
||||||
|
|
||||||
|
static class LineHolder extends RecyclerView.ViewHolder {
|
||||||
|
public TextView mode;
|
||||||
|
|
||||||
|
|
||||||
|
public LineHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
mode = itemView.findViewById(R.id.tv_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModeListAdapter(List<String> data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModeListAdapter.LineHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
// Create a new view
|
||||||
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.recycler_item, parent, false);
|
||||||
|
|
||||||
|
return new LineHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull LineHolder holder, final int position) {
|
||||||
|
// Set the username
|
||||||
|
String text = data.get(position);
|
||||||
|
System.out.println("Username: " + text);
|
||||||
|
holder.mode.setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -85,4 +85,15 @@
|
|||||||
android:text="Singen"
|
android:text="Singen"
|
||||||
app:layout_constraintStart_toEndOf="@+id/textView"
|
app:layout_constraintStart_toEndOf="@+id/textView"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/state" />
|
app:layout_constraintTop_toBottomOf="@+id/state" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerv"
|
||||||
|
android:layout_width="409dp"
|
||||||
|
android:layout_height="540dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/btnSingen"
|
||||||
|
app:layout_constraintVertical_bias="1.0" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
18
app/src/main/res/layout/recycler_item.xml
Normal file
18
app/src/main/res/layout/recycler_item.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_mode"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:text="TextView"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -7,7 +7,7 @@ buildscript {
|
|||||||
|
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.1'
|
classpath 'com.android.tools.build:gradle:3.6.3'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Wed Apr 15 23:02:08 CEST 2020
|
#Sun Apr 26 20:33:59 CEST 2020
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
||||||
|
Reference in New Issue
Block a user