Raj*_*ram 5 android android-edittext android-4.0-ice-cream-sandwich
这是一个我只面临> Android 4.0设备的问题.
目前我有一个listView和一个自定义标题,我添加了ListActivity的onCreate().
我在应用程序中将editText用作自定义searchBar.
以下是一个代码片段,希望能够解释我的实现.
private ListView lst_Reports = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showreportlist);
lst_Reports = (ListView) findViewById(R.id.VuoShowReportsActivity_Lst_Reports);
/*
* Initialize UI
*/
LinearLayout headerView = (LinearLayout) View.inflate(this, R.layout.report_list_header, null);
EditText reportSearchBar = (EditText) headerView.findViewById(R.id.reportSearchBar);
lst_Reports.addHeaderView(headerView);
reportSearchBar.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// do a search as and when the user inputs text
if (s != null && s.length() > 0) {
String query = s.toString();
List queriedReports = getReportsBasedOnQueryString(query);
// populate the listView with the queriedReports
}
}
});
}
protected List getReportsBasedOnQueryString(String query) {
// TODO Auto-generated method stub
return null;
}
当这个代码在Android 2.3.5设备上执行时,我可以在editText中正常输入.然而,当同样的代码部署在具有Ice cream三明治的Galaxy S3上时,我只能在editText中一次输入一个字符,因为它在每次键输入后都会失去焦点.
我已经尝试过以下针对类似问题提出的解决方案.他们都没有解决这个问题.
到AndroidManifest中的活动:
在活动的布局xml中:
我感谢任何关于此的帮助/反馈,并且也很想知道是否有其他人报告了同样的问题.
谢谢Rajat
public void onTextChanged(CharSequence s, int start, int before, int count) {
// do a search as and when the user inputs text
if (s != null && s.length() > 0) {
String query = s.toString();
List queriedReports = getReportsBasedOnQueryString(query);
// populate the listView with the queriedReports
}
// add below line in your code
reportSearchBar.requestFocus();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
502 次 |
| 最近记录: |