問題描述
我正在編寫一個活動來列??出數據庫中的一堆項目并顯示一個帶有數量的附加列.我實現了一個 ArrayAdapter 來顯示我的自定義布局.下面是Adapter最重要部分的代碼:
I'm writing an activity to list a bunch of items from the database and show an additional column with a quantity. I implemented an ArrayAdapter to show my custom layout. Here is the code of the most important parts of the Adapter:
static class ViewHolder {
protected TextView text;
protected EditText editText;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowquantitylayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.editText = (EditText) view.findViewById(R.id.editText);
viewHolder.editText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.i(TAG, "Editable:" + s.toString());
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
view.setTag(viewHolder);
viewHolder.editText.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).editText.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getDescription());
holder.editText.setText("" + list.get(position).getQuantity());
return view;
}
現在,當我嘗試聚焦EditText"時,它會在我單擊它后失去焦點.它顯示了 keboard,它甚至到達了 Log.i,但由于它沒有聚焦,所以不允許我更改值.
Now, when I try to focus the "EditText" it loses focus just after I clicked it. It shows the keboard and it even gets to the Log.i, but doesnt let me change the value since it is not focused.
感謝您的幫助
推薦答案
我遇到了同樣的問題,我正在尋找答案.這是對類似問題的回答:https://stackoverflow.com/a/9338694/1448661
I had the same problem and I searched for an answer. Here is an answer to a similar question : https://stackoverflow.com/a/9338694/1448661
您必須在清單中的活動中添加一行:
You have to put a line in your activity in the manifest :
android:windowSoftInputMode="adjustPan"
你的列表視圖也必須有這一行:
And your listview must have this line too :
android:descendantFocusability="beforeDescendants"
現在您可能會面臨另一個問題,即滾動時文本丟失.如果發生這種情況,請查看本教程:http://vikaskanani.wordpress.com/2011/07/27/android-focusable-edittext-inside-listview/
And now you will probably face another problem which is the lost of your text when scrolling. If this happens take a look at this tutorial : http://vikaskanani.wordpress.com/2011/07/27/android-focusable-edittext-inside-listview/
希望這會有所幫助.勾芡
Hope this will help. Goui
這篇關于EditText 失去對點擊的關注的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!