我在列表视图中有一个编辑文本。 Listview是使用Base Adapter创建的,并使用Holders加载编辑文本。
当我cal holder.edtText.hasFocus()时,它总是返回false。我在ListView属性中缺少的任何东西?
public View getView(final int position, View convertView, final
ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.screen, parent, false);
holder = new Adapter.ViewHolder(convertView);
convertView.setTag(holder);
}
else
{
holder = (Adapter.ViewHolder) convertView.getTag();
}
holder.edt.setCursorVisible(holder.edt.hasFocus());
holder.edt.setEnabled(true);
holder.edt.setTag(R.string.view, “some object”);
if (position == 10)
{
holder.edt.requestFocus();
}
holder.edt.setFilters(new Filter());
holder.edt.addTextChangedListener(new Watcher());
holder.edt.setText(“text”);
holder.edt.setSelection(text.length);
holder.edt.setSelectAllOnFocus(true);
return convertView;
}
public class ViewHolder extends RecyclerView.ViewHolder
{
public EditText edit;
public ViewHolder(View itemView)
{
super(itemView);
edt = (EditText) itemView.findViewById(R.id.edt);
}
}
答案 0 :(得分:1)
尝试添加
android:descendantFocusability="afterDescendants"
到你的listView
答案 1 :(得分:1)
尝试这样做,
static boolean b= true;
if(b == true){
et.requestFocus();
b= false;
}