implenented left and right layout
This commit is contained in:
1
.idea/codeStyles/Project.xml
generated
1
.idea/codeStyles/Project.xml
generated
@@ -94,7 +94,6 @@
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
|
||||
12
.idea/gradle.xml
generated
12
.idea/gradle.xml
generated
@@ -1,15 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<compositeConfiguration>
|
||||
<compositeBuild compositeDefinitionSource="SCRIPT" />
|
||||
</compositeConfiguration>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
25
.idea/jarRepositories.xml
generated
Normal file
25
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="BintrayJCenter" />
|
||||
<option name="name" value="BintrayJCenter" />
|
||||
<option name="url" value="https://jcenter.bintray.com/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
|
||||
@@ -5,13 +5,16 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
public class MainActivity extends AppCompatActivity implements Runnable {
|
||||
|
||||
ArrayList<Message> mData;
|
||||
Handler mHandler;
|
||||
MyAdapter myAdapter;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -21,10 +24,29 @@ public class MainActivity extends AppCompatActivity {
|
||||
mData.add(new Message("Joel", "Eine super Nachricht", new Date()));
|
||||
mData.add(new Message("Max", "Eine Nachricht", new Date()));
|
||||
|
||||
MyAdapter myAdapter = new MyAdapter(mData);
|
||||
myAdapter = new MyAdapter(mData);
|
||||
RecyclerView mRecyclerView = findViewById(R.id.recyclerView);
|
||||
LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||
mRecyclerView.setAdapter(myAdapter);
|
||||
mHandler = new Handler();
|
||||
mHandler.postDelayed(this, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int randNr = (int) Math.floor(Math.random() * 3);
|
||||
switch (randNr){
|
||||
case 0:
|
||||
mData.add(new Message("Niklas", "Eine super duper Nachricht", new Date()));
|
||||
break;
|
||||
case 1:
|
||||
mData.add(new Message("Joel", "Eine super Nachricht", new Date()));
|
||||
break;
|
||||
case 2:
|
||||
mData.add(new Message("Max", "Eine Nachricht", new Date()));
|
||||
}
|
||||
myAdapter.notifyDataSetChanged();
|
||||
mHandler.postDelayed(this, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.recyclerview;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -10,7 +11,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {
|
||||
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
ArrayList<Message> mData;
|
||||
|
||||
@@ -18,23 +19,51 @@ public class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {
|
||||
mData = aData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position % 2;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
View newView = inflater.inflate(R.layout.message_layout, parent, false);
|
||||
MyViewHolder myViewHolder = new MyViewHolder(newView);
|
||||
return myViewHolder;
|
||||
switch (viewType) {
|
||||
case 1:
|
||||
View newViewRight = inflater.inflate(R.layout.message_layout_right, parent, false);
|
||||
return new MyViewHolderRight(newViewRight);
|
||||
case 0:
|
||||
default:
|
||||
View newViewLeft = inflater.inflate(R.layout.message_layout_left, parent, false);
|
||||
return new MyViewHolderLeft(newViewLeft);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
TextView sender = holder.mTextView.findViewById(R.id.sender_tv);
|
||||
sender.setText(mData.get(position).sender);
|
||||
TextView text = holder.mTextView.findViewById(R.id.text_tv);
|
||||
text.setText(mData.get(position).text);
|
||||
TextView date = holder.mTextView.findViewById(R.id.date_tv);
|
||||
date.setText(mData.get(position).date.toString());
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
TextView sender;
|
||||
TextView text;
|
||||
TextView date;
|
||||
switch (holder.getItemViewType()) {
|
||||
case 1:
|
||||
MyViewHolderRight viewHolderRight = (MyViewHolderRight) holder;
|
||||
sender = viewHolderRight.mLinearLayout.findViewById(R.id.sender_tv);
|
||||
text = viewHolderRight.mLinearLayout.findViewById(R.id.text_tv);
|
||||
date = viewHolderRight.mLinearLayout.findViewById(R.id.date_tv);
|
||||
sender.setText(mData.get(position).sender);
|
||||
text.setText(mData.get(position).text);
|
||||
date.setText(mData.get(position).date.toString());
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
MyViewHolderLeft viewHolderLeft = (MyViewHolderLeft) holder;
|
||||
sender = viewHolderLeft.mLinearLayout.findViewById(R.id.sender_tv);
|
||||
text = viewHolderLeft.mLinearLayout.findViewById(R.id.text_tv);
|
||||
date = viewHolderLeft.mLinearLayout.findViewById(R.id.date_tv);
|
||||
sender.setText(mData.get(position).sender);
|
||||
text.setText(mData.get(position).text);
|
||||
date.setText(mData.get(position).date.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,10 +6,10 @@ import android.widget.LinearLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
LinearLayout mTextView;
|
||||
public MyViewHolder(@NonNull View itemView) {
|
||||
public class MyViewHolderLeft extends RecyclerView.ViewHolder {
|
||||
LinearLayout mLinearLayout;
|
||||
public MyViewHolderLeft(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
mTextView = (LinearLayout) itemView;
|
||||
mLinearLayout = (LinearLayout) itemView;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.recyclerview;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class MyViewHolderRight extends RecyclerView.ViewHolder {
|
||||
LinearLayout mLinearLayout;
|
||||
public MyViewHolderRight(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
mLinearLayout = (LinearLayout) itemView;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/message_layout_left"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="150dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sender_tv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView" />
|
||||
android:text="TextView"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:typeface="normal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_tv"
|
||||
30
app/src/main/res/layout/message_layout_right.xml
Normal file
30
app/src/main/res/layout/message_layout_right.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/message_layout_right"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginLeft="150dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sender_tv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_tv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="57dp"
|
||||
android:text="TextView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date_tv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
android:textAlignment="textEnd" />
|
||||
</LinearLayout>
|
||||
@@ -7,7 +7,7 @@ buildscript {
|
||||
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||
classpath 'com.android.tools.build:gradle:4.0.0-alpha08'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// 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 @@
|
||||
#Tue Jan 14 16:39:03 CET 2020
|
||||
#Sun Jan 19 10:43:18 CET 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-rc-1-all.zip
|
||||
|
||||
Reference in New Issue
Block a user