【问题标题】:Autosuggestion below the text inside the edittext android在edittext android内的文本下方自动提示
【发布时间】:2015-05-25 14:08:03
【问题描述】:

我想为edittext android中的键入文本制作带有自动提示功能的文本编辑器。

这是我正在尝试实现的设计。

我正在尝试在文本观察器中隐藏和显示列表视图 onTextChanged

class MyTextWatcher implements TextWatcher{

           @Override
           public void beforeTextChanged(CharSequence s, int start, int count, int after) {

           }

           @Override
           public void onTextChanged(CharSequence s, int start, int before, int count) {

    listView.setX(initialX);
    listView.setY(initialY);

           }

           @Override
           public void afterTextChanged(Editable s) {


           }
       }

这是好方法或告诉我正确的方法是什么?

【问题讨论】:

    标签: android autocomplete android-edittext


    【解决方案1】:

    试试这个:

     <AutoCompleteTextView
            android:id="@+id/Months"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:textStyle="bold"
            android:width="250dip" />
    

    在你的课堂上:

     AutoCompleteTextView textView=null;
    private ArrayAdapter<String> adapter;
    
    //These values show in autocomplete
    String item[]={
              "January", "February", "March", "April",
              "May", "June", "July", "August",
              "September", "October", "November", "December"
            };
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
    
        setContentView(R.layout.auto_complete_string);
    
    
        // Initialize AutoCompleteTextView values
    
            // Get AutoCompleteTextView reference from xml
            textView = (AutoCompleteTextView) findViewById(R.id.Months);
    
            //Create adapter    
            adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, item);
    
            textView.setThreshold(1);
    
           //Set adapter to AutoCompleteTextView
            textView.setAdapter(adapter);
            textView.setOnItemSelectedListener(this);
            textView.setOnItemClickListener(this);
    
    
    }
    
    
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
            long arg3) {
        // TODO Auto-generated method stub
        //Log.d("AutocompleteContacts", "onItemSelected() position " + position);
    }
    
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
    
        InputMethodManager imm = (InputMethodManager) getSystemService(
                INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    
    }
    
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
    
        // Show Alert       
        Toast.makeText(getBaseContext(), "Position:"+arg2+" Month:"+arg0.getItemAtPosition(arg2),
                Toast.LENGTH_LONG).show();
    
        Log.d("AutocompleteContacts", "Position:"+arg2+" Month:"+arg0.getItemAtPosition(arg2));
    
    }
    
    protected void onResume() {
        super.onResume();
    }
    
    protected void onDestroy() {
        super.onDestroy();
    }
    

    【讨论】:

    • 实际上我的edittext高度很大,如果我选择或重新输入我有类型的任何单词,我应该显示自动完成
    • @nambi 你有没有解决你的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多