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.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
@ -41,15 +42,17 @@ public class HospitalActivity extends BaseActivity {
private HospitalAdapter hospitalAdapter;
private int startNum = 1;
private int endNum = 10;
private int numberOfColumns=2;
List<GetHospitalApi.MemberBean> list=new ArrayList<>();
private int numberOfColumns = 2;
List<GetHospitalApi.MemberBean> list = new ArrayList<>();
private EditText et_search;
private Handler handler = new Handler();
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);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -58,12 +61,13 @@ public class HospitalActivity extends BaseActivity {
initView();
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() {
@Override
public void onFocusChange(View view, boolean b) {
InputKeyBoardUtils.show(HospitalActivity.this,view,b);
InputKeyBoardUtils.show(HospitalActivity.this, view, b);
}
});
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=findViewById(R.id.recyclerView);
MyGridLayoutManager gridLayoutManager= new MyGridLayoutManager(HospitalActivity.this,numberOfColumns);
recyclerView = findViewById(R.id.recyclerView);
MyGridLayoutManager gridLayoutManager = new MyGridLayoutManager(HospitalActivity.this, numberOfColumns);
gridLayoutManager.setUpView(et_search);
recyclerView.setLayoutManager(gridLayoutManager);
hospitalAdapter =new HospitalAdapter(list, new OnChildClickListener() {
hospitalAdapter = new HospitalAdapter(list, new OnChildClickListener() {
@Override
public <T> void onChildClick(View view, int position, T data) {
selectPostion = position;
GetHospitalApi.MemberBean memberBean= (GetHospitalApi.MemberBean) data;
if(position==list.size()-1){
startNum++;
GetHospitalApi.MemberBean memberBean = (GetHospitalApi.MemberBean) data;
if (memberBean.isLast()) {
startNum = startNum + endNum;
loadData(0);
}else {
HospitalDetailActivity.StartActivity(HospitalActivity.this,memberBean.getChosCode());
} else {
HospitalDetailActivity.StartActivity(HospitalActivity.this, memberBean.getChosCode());
}
}
});
recyclerView.setAdapter(hospitalAdapter);
recyclerView.addItemDecoration(new LinearSpacingItemDecoration(HospitalActivity.this,24));
recyclerView.addItemDecoration(new LinearSpacingItemDecoration(HospitalActivity.this, 24));
}
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)
.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>>>() {
@Override
public void onSucceed(HttpData<ApiResponse<GetHospitalApi>> stringHttpData) {
@ -136,14 +142,13 @@ public class HospitalActivity extends BaseActivity {
memberBean.setLast(true);
list.add(memberBean);
}
hospitalAdapter.notifyDataSetChanged();
if (type == 0) {
recyclerView.requestFocus();
recyclerView.post(new Runnable() {
@Override
public void run() {
View view = recyclerView.getLayoutManager().findViewByPosition(selectPostion);
View view = recyclerView.getLayoutManager().findViewByPosition(selectPostion - 1);
if (view != null) {
recyclerView.requestFocus();
view.requestFocus();

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

@ -54,6 +54,7 @@ public class MyGridLayoutManager extends GridLayoutManager {
switch (direction) {
case View.FOCUS_DOWN:
currentPosition = currentPosition + getSpanCount();
scrollToPosition(currentPosition);
break;
case View.FOCUS_UP:
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