AutoCompleteTextview的首字母缩写

时间:2016-05-06 08:56:55

标签: android autocompletetextview acronym

我是VietNamese,我用我的语言为我的应用程序使用自动完成TextView。我想制作自动完成TextView,当我输入自动完成TextView:“禁止”时,它理解我想找到:“bạn”或“bán”或“bàn”。这意味着:我的语言中的“a”字符可以理解:á或ạ或à。我怎么能这样做。

public class Google extends Activity {

    AutoCompleteTextView edSearch;
    RelativeLayout.LayoutParams layoutParams;

    RelativeLayout rl;
    RelativeLayout rl1;
    ImageView img1;
    ImageView img2;
    ImageView img3;
    ImageView img4;
    ImageView img5;
    ImageView img6;
    ImageView logoGoogle;
    int status = 0;
    int keyboardstatus = 0;
    DatabaseHelper database;
    final ArrayList<String> array = new ArrayList<String>();



    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_google);

        Intent returnIntent = new Intent();
        setResult(Activity.RESULT_OK, returnIntent);
        database = new DatabaseHelper(this);
       getListProduct();

        status = 0;
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array);

        edSearch = (AutoCompleteTextView) findViewById(R.id.search);
        rl = (RelativeLayout) findViewById(R.id.mylayout);
        rl1 = (RelativeLayout) findViewById(R.id.mylayout1);

        final Intent intent = new Intent(this, SecondActivity.class);
        img1 = (ImageView) findViewById(R.id.img1);
        img2 = (ImageView) findViewById(R.id.img2);
        img3 = (ImageView) findViewById(R.id.img3);
        img4 = (ImageView) findViewById(R.id.img4);
        img5 = (ImageView) findViewById(R.id.img5);
        img6 = (ImageView) findViewById(R.id.img6);
        img1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra("message", "Ebay");
                startActivity(intent);
            }
        });
        img2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra("message", "Tiger");
                startActivity(intent);
            }
        });
        img3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra("message", "Nice logo");
                startActivity(intent);
            }
        });
        img4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra("message", "adidas");
                startActivity(intent);
            }
        });
        img5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra("message", "b");
                startActivity(intent);
            }
        });
        img6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra("message", "Nice");
                startActivity(intent);
            }
        });
        logoGoogle = (ImageView) findViewById(R.id.googlelogo);
        edSearch.setBackgroundResource(R.drawable.focus_edittext);
        edSearch.setAdapter(adapter);
        edSearch.setThreshold(1);

        edSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int index = array.indexOf(edSearch.getText().toString());
                // System.out.println(array.get(index) + "  : " + index); //check it now in Logcat

                intent.putExtra("message", array.get(index));
                startActivity(intent);
                edSearch.setText("");

            }
        });

        layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        final float d = this.getResources().getDisplayMetrics().density;
        int top = (int) (300 * d);
        int left = (int) (20 * d);
        int right = (int) (20 * d);
        layoutParams.setMargins(left, top, right, 0);
        edSearch.setLayoutParams(layoutParams);

        rl.setBackgroundResource(R.color.white);
        rl1.setBackgroundResource(R.color.white);

        edSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    performSearch();
                    return true;
                }
                if (event.getAction() == KeyEvent.ACTION_UP) {

                    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                        edSearch.setText("da back");
                    }

                }

                return false;
            }
        });





        //---------

        //-------
        edSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                status = 1;
                // Toast.makeText(getApplicationContext(), status + " khi da click ", Toast.LENGTH_SHORT).show();
                final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) edSearch.getLayoutParams();
                ValueAnimator animator = ValueAnimator.ofInt(params.topMargin, 0);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        params.topMargin = (Integer) valueAnimator.getAnimatedValue();
                        edSearch.requestLayout();
                        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(edSearch.getWindowToken(), 0);
                    }
                });
                animator.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        layoutParams.setMargins(0, 0, 0, 0);
                        edSearch.setLayoutParams(layoutParams);
                        rl.setBackgroundResource(R.color.dark);
                        getApplication().setTheme(R.style.BlackTheme);
                        img1.setColorFilter(R.color.dark);
                        img2.setColorFilter(R.color.dark);
                        img3.setColorFilter(R.color.dark);
                        img4.setColorFilter(R.color.dark);
                        img5.setColorFilter(R.color.dark);
                        img6.setColorFilter(R.color.dark);
                        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edSearch, InputMethodManager.SHOW_IMPLICIT);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                animator.setDuration(200);
                animator.start();
            }
        });

1 个答案:

答案 0 :(得分:0)

您可以通过编写实现android.widget.Filterable接口的自定义适配器来实现此目的。 您的自定义过滤器可以处理不同类型的越南语。

public class MyAdapter extends ArrayAdapter<String> {

   private Filter myFilter;

   public Filter getFilter() {
       if (myFilter == null) {
            myFilter= new MyArrayFilter();
       }
       return myFilter;
   }

   private class MyArrayFilter extends ArrayFilter {
       @Override
       protected FilterResults performFiltering(CharSequence prefix) {
          // Perform your filtering here. For example replace all possible a-versions with the basic a
          // Note that it's run in a background thread, so no UI interaction from here
      }

      @Override
      protected void publishResults(CharSequence constraint, FilterResults results) {
         // Gets called on the UI thread when filtering is done
         // Second param is return value from performFilter call
         // Put your results to the interface here
      }
   }
}

您可以在this stackoverflow answer找到一个示例。