recycleview 移动调整 医院详情修改

dev
李桢 2 years ago
parent 914295a798
commit fc92e272a4
  1. 47
      app/src/main/java/com/unionmed/unionmedtv/activity/HospitalActivity.java
  2. 4
      app/src/main/java/com/unionmed/unionmedtv/adapter/HospitalAdapter.java
  3. 1
      app/src/main/java/com/unionmed/unionmedtv/utils/MyGridLayoutManager.java
  4. 39
      app/src/main/res/layout/item_load_more_layout1.xml

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
@ -41,15 +42,17 @@ public class HospitalActivity extends BaseActivity {
private HospitalAdapter hospitalAdapter; private HospitalAdapter hospitalAdapter;
private int startNum = 1; private int startNum = 1;
private int endNum = 10; private int endNum = 10;
private int numberOfColumns=2; private int numberOfColumns = 2;
List<GetHospitalApi.MemberBean> list=new ArrayList<>(); List<GetHospitalApi.MemberBean> list = new ArrayList<>();
private EditText et_search; private EditText et_search;
private Handler handler = new Handler(); private Handler handler = new Handler();
private int selectPostion = 0;//当前列表item点击位置 private int selectPostion = 0;//当前列表item点击位置
public static void StartActivity(Context context){
Intent intent=new Intent(context, HospitalActivity.class); public static void StartActivity(Context context) {
Intent intent = new Intent(context, HospitalActivity.class);
context.startActivity(intent); context.startActivity(intent);
} }
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -58,12 +61,13 @@ public class HospitalActivity extends BaseActivity {
initView(); initView();
loadData(1); loadData(1);
} }
public void initView(){
et_search=findViewById(R.id.et_search); public void initView() {
et_search = findViewById(R.id.et_search);
et_search.setOnFocusChangeListener(new View.OnFocusChangeListener() { et_search.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override @Override
public void onFocusChange(View view, boolean b) { public void onFocusChange(View view, boolean b) {
InputKeyBoardUtils.show(HospitalActivity.this,view,b); InputKeyBoardUtils.show(HospitalActivity.this, view, b);
} }
}); });
et_search.addTextChangedListener(new TextWatcher() { et_search.addTextChangedListener(new TextWatcher() {
@ -83,26 +87,27 @@ public class HospitalActivity extends BaseActivity {
} }
}); });
recyclerView=findViewById(R.id.recyclerView); recyclerView = findViewById(R.id.recyclerView);
recyclerView.requestFocus(); recyclerView.requestFocus();
recyclerView=findViewById(R.id.recyclerView); recyclerView = findViewById(R.id.recyclerView);
MyGridLayoutManager gridLayoutManager= new MyGridLayoutManager(HospitalActivity.this,numberOfColumns); MyGridLayoutManager gridLayoutManager = new MyGridLayoutManager(HospitalActivity.this, numberOfColumns);
gridLayoutManager.setUpView(et_search);
recyclerView.setLayoutManager(gridLayoutManager); recyclerView.setLayoutManager(gridLayoutManager);
hospitalAdapter =new HospitalAdapter(list, new OnChildClickListener() { hospitalAdapter = new HospitalAdapter(list, new OnChildClickListener() {
@Override @Override
public <T> void onChildClick(View view, int position, T data) { public <T> void onChildClick(View view, int position, T data) {
selectPostion = position; selectPostion = position;
GetHospitalApi.MemberBean memberBean= (GetHospitalApi.MemberBean) data; GetHospitalApi.MemberBean memberBean = (GetHospitalApi.MemberBean) data;
if(position==list.size()-1){ if (memberBean.isLast()) {
startNum++; startNum = startNum + endNum;
loadData(0); loadData(0);
}else { } else {
HospitalDetailActivity.StartActivity(HospitalActivity.this,memberBean.getChosCode()); HospitalDetailActivity.StartActivity(HospitalActivity.this, memberBean.getChosCode());
} }
} }
}); });
recyclerView.setAdapter(hospitalAdapter); recyclerView.setAdapter(hospitalAdapter);
recyclerView.addItemDecoration(new LinearSpacingItemDecoration(HospitalActivity.this,24)); recyclerView.addItemDecoration(new LinearSpacingItemDecoration(HospitalActivity.this, 24));
} }
private Runnable searchRunnable = new Runnable() { private Runnable searchRunnable = new Runnable() {
@ -114,9 +119,10 @@ public class HospitalActivity extends BaseActivity {
// ... // ...
} }
}; };
public void loadData(int type){
public void loadData(int type) {
EasyHttp.post(HospitalActivity.this) EasyHttp.post(HospitalActivity.this)
.api(new GetHospitalApi(et_search.getText().toString(),startNum, CacheUtil.getPkey(),endNum)) .api(new GetHospitalApi(et_search.getText().toString(), startNum, CacheUtil.getPkey(), endNum))
.request(new OnHttpListener<HttpData<ApiResponse<GetHospitalApi>>>() { .request(new OnHttpListener<HttpData<ApiResponse<GetHospitalApi>>>() {
@Override @Override
public void onSucceed(HttpData<ApiResponse<GetHospitalApi>> stringHttpData) { public void onSucceed(HttpData<ApiResponse<GetHospitalApi>> stringHttpData) {
@ -136,14 +142,13 @@ public class HospitalActivity extends BaseActivity {
memberBean.setLast(true); memberBean.setLast(true);
list.add(memberBean); list.add(memberBean);
} }
hospitalAdapter.notifyDataSetChanged(); hospitalAdapter.notifyDataSetChanged();
if (type == 0) { if (type == 0) {
recyclerView.requestFocus(); recyclerView.requestFocus();
recyclerView.post(new Runnable() { recyclerView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
View view = recyclerView.getLayoutManager().findViewByPosition(selectPostion); View view = recyclerView.getLayoutManager().findViewByPosition(selectPostion - 1);
if (view != null) { if (view != null) {
recyclerView.requestFocus(); recyclerView.requestFocus();
view.requestFocus(); view.requestFocus();

@ -32,7 +32,7 @@ public class HospitalAdapter extends BaseDelegateMultiAdapter<GetHospitalApi.Mem
@Override @Override
public int getItemType(@NotNull List<? extends GetHospitalApi.MemberBean> data, int position) { public int getItemType(@NotNull List<? extends GetHospitalApi.MemberBean> data, int position) {
// 根据数据,自己判断应该返回的类型 // 根据数据,自己判断应该返回的类型
if (position == data.size()-1) { if (data.get(position).isLast()) {
return 0; return 0;
} else { } else {
return 1; return 1;
@ -40,7 +40,7 @@ public class HospitalAdapter extends BaseDelegateMultiAdapter<GetHospitalApi.Mem
} }
}); });
getMultiTypeDelegate() getMultiTypeDelegate()
.addItemType(0, R.layout.item_load_more_layout) .addItemType(0, R.layout.item_load_more_layout1)
.addItemType(1, R.layout.item_type_hospital_layout); .addItemType(1, R.layout.item_type_hospital_layout);
} }

@ -54,6 +54,7 @@ public class MyGridLayoutManager extends GridLayoutManager {
switch (direction) { switch (direction) {
case View.FOCUS_DOWN: case View.FOCUS_DOWN:
currentPosition = currentPosition + getSpanCount(); currentPosition = currentPosition + getSpanCount();
scrollToPosition(currentPosition);
break; break;
case View.FOCUS_UP: case View.FOCUS_UP:
if (currentPosition % getSpanCount() == 0 && upView != null) { if (currentPosition % getSpanCount() == 0 && upView != null) {

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<com.unionmed.unionmedtv.widgets.ImgConstraintLayout 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"
style="@style/FocusStyle"
android:layout_width="396dp"
android:layout_height="222dp"
android:background="@drawable/shape_corners10_color_1b4765">
<ImageView
android:id="@+id/iv_type_three_poster"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription" />
<RelativeLayout
android:id="@+id/tv"
android:layout_width="396dp"
android:layout_height="222dp">
<TextView
android:id="@+id/tv_load_more"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="点击加载\n更多数据"
android:textSize="21sp"
android:textColor="@color/white_f1f1f1"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_focus_selector"
android:duplicateParentState="true"
android:scaleType="fitXY"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</com.unionmed.unionmedtv.widgets.ImgConstraintLayout>
Loading…
Cancel
Save