片段中的微调变慢?

时间:2017-03-30 03:17:14

标签: android android-fragments

我在片段中添加了一个微调器。它有效但不像我预期的那样。选择时微调器很慢并且没有响应。在没有过滤器的logcat中,它将返回错误消息:窗口已经聚焦,忽略微调器的焦点增益 W / InputEventReceiver:尝试完成输入事件但输入事件接收器已经已被处理。这是我的代码:`

public class FourthTab extends Fragment implements OnItemSelectedListener` {

private View rootView;
private ViewGroup container;

public FourthTab() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {


    rootView = inflater.inflate(R.layout.fourth_tab, container, false);
    this.container = container;

    makeSpinner(rootView, getContext());

    return rootView;
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // On selecting a spinner item
    String item = parent.getItemAtPosition(position).toString();

    // Showing selected spinner item

    //TextView tes = (TextView) rootView.findViewById(R.id.tes);
    //tes.setText(item);



    Handler mhandler = new Handler();
    mhandler.postDelayed(new DisplayToast(getContext(), "Selected2: " + item), 100 );

}
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub
}


/*agar prosess calling ke network hanya dilakukan apabila fragment terlihat    */
@Override
public void setUserVisibleHint(boolean visible)
{
    super.setUserVisibleHint(visible);
    if (visible && isResumed())
    {
        //Only manually call onResume if fragment is already visible
        //Otherwise allow natural fragment lifecycle to call onResume
        onResume();
    }
}

@Override
public void onResume()
{
    super.onResume();
    if (!getUserVisibleHint())
    {
        return;
    }



}

private void makeSpinner(View rootView, Context context) {

    // Spinner element
    Spinner spinner = (Spinner) rootView.findViewById(R.id.semester_spinner);

    // Spinner click listener
    spinner.setOnItemSelectedListener(this);

    // Spinner Drop down elements
    List<String> categories = new ArrayList<String>();
    categories.add("Automobile");
    categories.add("Business Services");
    categories.add("Computers");
    categories.add("Education");
    categories.add("Personal");
    categories.add("Travel");

    // Creating adapter for spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_spinner_item, categories);

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    spinner.setAdapter(dataAdapter);

}

请有人建议发生什么事吗?我已经尝试过这种方法:https://www.laurivan.com/attempted-to-finish-an-input-event/  但它仍然没有用,我试图在谷歌上找到这个错误 窗口已经集中,W / InputEventReceiver:尝试完成输入事件,但输入事件接收器已被处理。 忽略微调器的焦点增益这里是我的代码,但从来没有得到任何好处。谢谢你

public class DisplayToast implements Runnable {
private final Context mContext;
private final String mText;

public DisplayToast(Context mContext, String text) {
    this.mContext = mContext;
    mText = text;
}

public void run() {
    Toast.makeText(mContext, mText, Toast.LENGTH_SHORT).show();
}

1 个答案:

答案 0 :(得分:0)

当有人对我的问题发表评论时,我开始怀疑这是关于集成设备/模拟器的。所以我安装genymotion模拟器来试试这个。幸运的是它有效。

默认模拟器是:Nexus 5 API 21 和geny运动模拟器是三星S3

希望它会让其他人获得通知