在android中水平自动完成单词建议

时间:2011-01-26 10:48:09

标签: android autocomplete android-edittext

我需要自动完成单词建议。当我点击自动完成编辑文本框中的“th”时,它会显示“那个”,“那里”,“那些”...就像在垂直列表视图上那样。我需要在水平方向上显示结果(那里,那些..)。我怎么能这样做?

我的代码是:

public class AutoCompleteDemo extends Activity
implements TextWatcher {
TextView selection;
AutoCompleteTextView edit;

String[] items={"lorem", "ipsum", "dolor", "sit", "amet",
"consectetuer", "adipiscing", "elit", "morbi", "vel",
"ligula", "vitae", "arcu", "aliquet", "mollis",
"etiam", "vel", "erat", "placerat", "ante",
"porttitor", "sodales", "pellentesque", "augue", "purus"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

edit=(AutoCompleteTextView)findViewById(R.id.edit);
edit.addTextChangedListener(this);
edit.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple dropdown item 1line,
items));
}


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

}


public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// needed for interface, but not used
}


public void afterTextChanged(Editable s) {
// needed for interface, but not used
}
}

0 个答案:

没有答案