在将软输入状态设置为隐藏时,Recycler View不会加载

时间:2018-06-13 05:34:29

标签: android android-recyclerview recycler-adapter

  

适用于Recycler View的适配器:

public class FeelingAdapter extends 
RecyclerView.Adapter<FeelingAdapter.MyViewHolder> {
private Context mContext;
private boolean firstLoad;
private static MyClickListener myClickListener;
private int prevfeeling=2;
private List<Feeling> feelings;

public class MyViewHolder extends ViewHolder implements View.OnClickListener {
    public TextView feeling;
    public ImageView sym;

    public MyViewHolder(View view) {
        super(view);
        view.setOnClickListener(this);
        feeling = (TextView) view.findViewById(R.id.symptom_name);
        sym= (ImageView) view.findViewById(R.id.symptom);
    }


    @Override
    public void onClick(View v) {
        myClickListener.onItemClick(getAdapterPosition(), v);
    }
}
public void setOnItemClickListener(MyClickListener myClickListener) {
    FeelingAdapter.myClickListener = myClickListener;
}
public FeelingAdapter(List<Feeling> feelingsList) {
    this.feelings = feelingsList;
    this.firstLoad = true;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.feeling_button, parent, false);

    return new MyViewHolder(itemView);
}

public void changeImage(int index) {
    feelings.get(index).setImageChanged(true);
    if(prevfeeling!=-1) {
        feelings.get(prevfeeling).setImageChanged(false);
        notifyItemChanged(prevfeeling);
    }
    notifyItemChanged(index);
    prevfeeling=index;
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    Feeling feeling = feelings.get(position);
    holder.feeling.setText(feeling.getSymptom_name());
    String url = feeling.getImgUrl();
    if(feeling.isImageChanged()){
        GlideApp.with(holder.itemView).load(feeling.getImgSelUrl()).fitCenter().placeholder(R.drawable.allergies).into(holder.sym);
    }
    else
       if(position==2) {
        if(firstLoad) {
            GlideApp.with(holder.itemView).load(feeling.getImgSelUrl()).fitCenter().placeholder(R.drawable.allergies).into(holder.sym);
            firstLoad=false;
        }
        else
            GlideApp.with(holder.itemView).load(feeling.getImgUrl()).fitCenter().placeholder(R.drawable.allergies).into(holder.sym);
       }
    else
        GlideApp.with(holder.itemView).load(url).fitCenter().placeholder(R.drawable.allergies).into(holder.sym);
    }

@Override
public int getItemCount() {
    return feelings.size();
}
public interface MyClickListener {
    void onItemClick(int position, View v);
}
}
  

主要活动中的回收站视图:

mAdapter = new FeelingAdapter(fl);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
    recyclerView.setAdapter(mAdapter);
    mAdapter.notifyDataSetChanged();
    mAdapter.setOnItemClickListener((new FeelingAdapter.MyClickListener() {
        @Override
        public void onItemClick(int position, View v) {
            Log.i("ItemClicked", " Clicked on Item " + position);
            if(curSymptomPosition==position) {
                mAdapter.changeImage(position);
                mMap.clear();
            }
            else {
                curSymptomPosition = position;
                mAdapter.changeImage(position);
                mMap.clear();
                getFeelings(position + 1);
            }

           /*infoBox.setVisibility(View.VISIBLE);
           crsBtn.setVisibility(View.VISIBLE);*/

        }
    }));

当我在主要活动的清单文件中添加以下行时:

android:windowSoftInputMode="stateAlwaysHidden"

键盘在进入我的主要活动时不会自动打开,但不会显示回收站视图。即使我从XML布局中删除了editText,这个问题仍然存在。

  

activity_main.xml中

<RelativeLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:background="@color/white"
    tools:context="com.photon.legacyhealth.MainActivity">

    <com.photon.legacyhealth.PresetRadioGroup
        android:id="@+id/preset_time_radio_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_margin="0dp"
        android:layout_marginBottom="13dp"
        android:orientation="horizontal"
        android:weightSum="2"
        app:presetRadioCheckedId="@+id/preset_time_value_button_30">

        <com.photon.legacyhealth.PresetValueButton
            android:id="@+id/preset_time_value_button_30"
            style="@style/PresetLayoutButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:presetButtonValueText="Feeling" />

        <com.photon.legacyhealth.PresetValueButton
            android:id="@+id/preset_time_value_button_60"
            style="@style/PresetLayoutButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:presetButtonValueText="Doing" />
    </com.photon.legacyhealth.PresetRadioGroup>
<AutoCompleteTextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/zipcode"
    android:layout_below="@id/preset_time_radio_group"
    android:hint="@string/ziptext"
    android:fontFamily="@font/lato_light"
    android:textSize="14sp"
    android:textColorHint="@color/hintcolor"
    android:paddingLeft="12.5dp"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_below="@id/zipcode"
    android:layout_height="match_parent">
</FrameLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:layout_width="wrap_content"
    android:background="@drawable/rounded_corner"
    android:elevation="12dp"
    android:outlineProvider="bounds"
    android:layout_height="wrap_content"
    android:layout_marginLeft="350dp"
    android:layout_marginTop="120dp"
    android:orientation="vertical" />
</RelativeLayout>

如果没有回收者视图消失,如何隐藏键盘?当软输入状态未被隐藏时,回收者视图将完美显示。

0 个答案:

没有答案