RecyclerView.Adapter

This commit is contained in:
Rao 2024-06-16 01:27:52 +08:00
parent 8151d0d807
commit adf88f8162
6 changed files with 68 additions and 87 deletions

View File

@ -47,4 +47,6 @@ dependencies {
implementation ("io.github.scwang90:refresh-header-two-level:2.1.0") //二级刷新头
implementation ("io.github.scwang90:refresh-footer-ball:2.1.0") //球脉冲加载
implementation ("io.github.scwang90:refresh-footer-classics:2.1.0")
}

View File

@ -1,8 +1,8 @@
package com.hnucm.c202201020141;
public class Chat {
public String name;
public String content;
public String time;
public String doctor;
public String num;
public String imgurl;
}

View File

@ -1,11 +1,6 @@
package com.hnucm.c202201020141;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -13,6 +8,12 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
@ -32,12 +33,11 @@ public class HomeActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_home2);
for(int i=0;i<20;i++){
Chat chat=new Chat();
chat.name="姓名"+i;
chat.content="聊天内容"+i;
chat.time="聊天时间"+i;
chat.doctor="姓名"+i;
chat.num="聊天内容"+i;
chatList.add(chat);
}
@ -56,9 +56,8 @@ public class HomeActivity2 extends AppCompatActivity {
//构造一些数据 ->todo 网络请求得到
for(int i=0;i<20;i++){
Chat chat=new Chat();
chat.name="姓名"+i;
chat.content="聊天内容"+i;
chat.time="聊天时间"+i;
chat.doctor="姓名"+i;
chat.num="聊天内容"+i;
chatList.add(chat);
}
smartRefreshLayout.finishRefresh(2000);
@ -72,9 +71,9 @@ public class HomeActivity2 extends AppCompatActivity {
//上拉加载
for(int i=0;i<20;i++){
Chat chat=new Chat();
chat.name="姓名"+i;
chat.content="聊天内容"+i;
chat.time="聊天时间"+i;
chat.doctor="姓名"+i;
chat.num="聊天内容"+i;
chatList.add(chat);
}
smartRefreshLayout.finishLoadMore(2000);
@ -111,17 +110,16 @@ public class HomeActivity2 extends AppCompatActivity {
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
Chat chat=chatList.get(position);
holder.textView.setText(chatList.get(position).name);
holder.textView2.setText(chatList.get(position).content);
holder.textView3.setText(chatList.get(position).time);
holder.Layout.setOnClickListener(new View.OnClickListener() {
holder.textView.setText(chatList.get(position).doctor);
holder.textView2.setText(chatList.get(position).num);
/*holder.Layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(HomeActivity2.this, ChatActivity.class);
Intent intent=new Intent(MainActivity.this, ChatActivity.class);
intent.putExtra("name",chat.name);
startActivity(intent);
}
});
});*/
}
//显示item的条数

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -4,22 +4,18 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity2">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="409dp"
android:layout_height="580dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView24">
tools:context=".MainActivity">
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/smartlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="600dp"
android:layout_marginBottom="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
@ -27,50 +23,34 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="@+id/imageView24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/_2024_06_14_191105" />
<ImageView
android:id="@+id/imageView25"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/_2024_06_14_191544" />
<TextView
android:id="@+id/textView28"
android:id="@+id/textView24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginTop="56dp"
android:text="专家分类"
android:textSize="16sp"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/smartlayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/imageView21"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="32dp"
android:layout_marginTop="64dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/_2024_06_14_191544" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -36,13 +36,14 @@
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView
android:id="@+id/textView3"
android:layout_width="80dp"
android:layout_height="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:text="TextView"
<ImageView
android:id="@+id/imageView23"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="28dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/_2024_06_16_011738" />
</androidx.constraintlayout.widget.ConstraintLayout>