Android layout 在手机中运行apk时,键盘在自定义微调器下拉菜单Edittext中焦点未打开

Android layout 在手机中运行apk时,键盘在自定义微调器下拉菜单Edittext中焦点未打开,android-layout,android-fragments,Android Layout,Android Fragments,问题是在编辑文本的焦点上并没有打开键盘,并且无法编辑 If i Place <requestfocus /> in xml then the code is crashed. 如果我将其放入xml,那么代码就会崩溃。 请尽快解决我的问题。 这个搜索栏类似于Gmail搜索栏 MainActivity.XML代码 <FrameLayout android:id="@+id/rellayout" android:layout_width="matc

问题是在编辑文本的焦点上并没有打开键盘,并且无法编辑

    If i Place <requestfocus /> in xml then the code is crashed.
如果我将其放入xml,那么代码就会崩溃。
请尽快解决我的问题。 这个搜索栏类似于Gmail搜索栏

MainActivity.XML代码

    <FrameLayout
    android:id="@+id/rellayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/linearLayout1"
    android:layout_alignTop="@+id/search"
    android:layout_toLeftOf="@+id/search" >

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="Search"
        android:descendantFocusability="afterDescendants" />



    <Spinner android:id="@+id/dropspinner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:descendantFocusability="afterDescendants"
        style="@android:style/Widget.DeviceDefault.EditText" />

    <ImageView
        android:id="@+id/dropdownimage"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/dropdown"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="10dp" />

</FrameLayout>

DropDown.XML

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f0f0f0f0"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView

    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Crop:"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#000" />

    <EditText
    android:id="@+id/crop"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="XYZ"
    android:layout_marginTop="2dp"
    android:background="#FFF"
    android:padding="3dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1" >


    </EditText>

    <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#000"
    android:layout_alignLeft="@+id/crop"
    android:layout_below="@+id/crop"
    android:text="Posted By:"
    android:layout_marginTop="2dp" />

    <EditText
    android:id="@+id/postedby"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:ems="10"
    android:hint="XYZ"
    android:layout_marginTop="2dp"
    android:background="#FFF"
    android:padding="3dp" />

    <TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#000"
    android:layout_alignLeft="@+id/postedby"
    android:layout_below="@+id/postedby"
    android:text="Location"
    android:layout_marginTop="2dp" />

    <EditText
    android:id="@+id/location"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView3"
    android:layout_below="@+id/textView3"
    android:ems="10"
    android:hint="Example Agra"
    android:layout_marginTop="2dp"
    android:background="#FFF"
    android:padding="3dp" />

    <Button
    android:id="@+id/searchdropdown"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/location"
    android:layout_below="@+id/location"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:text="Search"
    android:textColor="#FFF"
    android:textStyle="bold"
    android:background="@drawable/rounded_shape_button_green" />

    </LinearLayout>

Product.java

    import java.util.ArrayList;
    import java.util.List;

    import com.aksha.adapters.DropDownAutoComplete;
    import com.aksha.adapters.LazyAdapter;
    import com.aksha.adapters.MyObject;
    import com.aksha.adapters.RefreshableListView;

    import android.content.Context;
    import android.graphics.Typeface;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.view.LayoutInflater;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.View.OnTouchListener;
    import android.view.ViewGroup;
    import android.view.inputmethod.InputMethodManager;
    import android.widget.Adapter;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.AutoCompleteTextView;
    import android.widget.ImageView;
    import android.widget.Spinner;

    public class Product extends Fragment {

        private RefreshableListView mListView;
        private ArrayList<String> stringAdapter;

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup         container,
                Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            View rootView = inflater.inflate(R.layout.product,container, false);
            Typeface hindi =         Typeface.createFromAsset(getActivity().getAssets(), "fonts/DroidHindi.ttf");
    stringAdapter = new ArrayList<String>();
    stringAdapter.add("abcde");
    stringAdapter.add("abcdef");
    stringAdapter.add("abcdefg");

    final ImageView search = (ImageView) rootView.findViewById(R.id.search);
    final ImageView dropdownimage = (ImageView) rootView.findViewById(R.id.dropdownimage);
    final Spinner drop = (Spinner) rootView.findViewById(R.id.dropspinner);
    drop.setClickable(false);
    final AutoCompleteTextView actv = (AutoCompleteTextView)rootView.findViewById(R.id.autoCompleteTextView1);
    actv.setThreshold(1);
    mListView = ((RefreshableListView)rootView.findViewById(R.id.today_refreshable_list));

    dropdownimage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            drop.performClick();
            actv.clearFocus();
        }
    });

    ArrayList<MyObject> object = new ArrayList<MyObject>();
    object.add(new MyObject("ABC"));
    drop.setAdapter(null);
    drop.setAdapter(new DropDownAutoComplete(getActivity(), R.layout.dropdown, object, mListView, drop));

    if(stringAdapter.size()>0){
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line, stringAdapter);
        actv.setAdapter(adapter);
    }

    actv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            search.performClick();
        }
    });

    mListView.setOnRefreshListener(new RefreshableListView.OnRefreshListener()
    {
    public void onRefresh(RefreshableListView paramAnonymousRefreshableListView)
    {
    try{
    stringAdapter.add("abcdefg");
    LazyAdapter adapter = new LazyAdapter(getActivity(), stringAdapter);
                mListView.setAdapter(adapter);
                mListView.completeRefreshing();
    }catch(Exception e){
                e.getMessage();
    }
        }
    });

    search.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            try{
                LazyAdapter adapter = new LazyAdapter(getActivity(), stringAdapter);
                mListView.setAdapter(adapter);
            }catch(Exception e){
                e.getMessage();
            }
        }
    });

    return rootView;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
    // TODO Auto-generated method stub
    super.setUserVisibleHint(isVisibleToUser);
    try{
        if(isVisibleToUser){
            //Code
        }
    }catch(Exception e){
        e.getMessage();
    }
    }

    }
import java.util.ArrayList;
导入java.util.List;
导入com.aksha.adapters.DropDownAutoComplete;
导入com.aksha.adapters.LazyAdapter;
导入com.aksha.adapters.MyObject;
导入com.aksha.adapters.RefreshableListView;
导入android.content.Context;
导入android.graphics.Typeface;
导入android.os.Bundle;
导入android.support.v4.app.Fragment;
导入android.text.Editable;
导入android.text.TextWatcher;
导入android.view.LayoutInflater;
导入android.view.MotionEvent;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.view.view.OnTouchListener;
导入android.view.ViewGroup;
导入android.view.inputmethod.InputMethodManager;
导入android.widget.Adapter;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.AdapterView.OnItemSelectedListener;
导入android.widget.ArrayAdapter;
导入android.widget.AutoCompleteTextView;
导入android.widget.ImageView;
导入android.widget.Spinner;
公共类产品扩展片段{
私有刷新列表视图mListView;
私有ArrayList字符串适配器;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//TODO自动生成的方法存根
视图根视图=充气机。充气(右布局。产品,容器,假);
Typeface hindi=Typeface.createFromAsset(getActivity().getAssets(),“fonts/DroidHindi.ttf”);
stringAdapter=newArrayList();
stringAdapter.add(“abcde”);
stringAdapter.add(“abcdef”);
stringAdapter.add(“abcdefg”);
最终ImageView搜索=(ImageView)rootView.findViewById(R.id.search);
最终ImageView-dropdownimage=(ImageView)rootView.findViewById(R.id.dropdownimage);
最终微调器下降=(微调器)rootView.findViewById(R.id.dropspinner);
drop.setClickable(假);
final AutoCompleteTextView actv=(AutoCompleteTextView)rootView.findviewbyd(R.id.AutoCompleteTextView 1);
动作设定阈值(1);
mListView=((RefreshTableListView)rootView.findViewById(R.id.today\u RefreshTable\u list));
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
drop.performClick();
actv.clearFocus();
}
});
ArrayList对象=新的ArrayList();
添加(新的MyObject(“ABC”));
drop.setAdapter(null);
setAdapter(新的DropDownAutoComplete(getActivity(),R.layout.dropdown,object,mListView,drop));
如果(stringAdapter.size()>0){
ArrayAdapter=新的ArrayAdapter(getActivity(),android.R.layout.simple\u下拉菜单\u item\u 1line,stringAdapter);
actv.setAdapter(适配器);
}
actv.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
公共链接(AdapterView arg0、视图arg1、内部arg2、,
长arg3){
//TODO自动生成的方法存根
search.performClick();
}
});
mListView.setOnRefreshListener(新的RefreshTableListView.OnRefreshListener()
{
公共void onRefresh(RefreshableListView参数匿名RefreshableListView)
{
试一试{
stringAdapter.add(“abcdefg”);
LazyAdapter=新的LazyAdapter(getActivity(),stringAdapter);
mListView.setAdapter(适配器);
mListView.completeRefreshing();
}捕获(例外e){
e、 getMessage();
}
}
});
search.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
试一试{
LazyAdapter=新的LazyAdapter(getActivity(),stringAdapter);
mListView.setAdapter(适配器);
}捕获(例外e){
e、 getMessage();
}
}
});
返回rootView;
}
@凌驾
public void setUserVisibleHint(布尔值isVisibleToUser){
//TODO自动生成的方法存根
super.setUserVisibleHint(isVisibleToUser);
试一试{
如果(isVisibleToUser){
//代码
}
}捕获(例外e){
e、 getMessage();
}
}
}
DropDownAutoComplete.java