gpt4 book ai didi

Android listview 项目没有获得焦点

转载 作者:太空狗 更新时间:2023-10-29 14:12:06 26 4
gpt4 key购买 nike

我的 ListView 中的项目没有获得焦点,我的 onFocusChanged 没有工作所以我创建了一个日志语句来记录焦点并且我总是为 v.isFocused() 的结果返回“false”。

onClick 方法工作正常。

有什么想法吗?

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
final ExerciseListHolder holder;

if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);

holder = new ExerciseListHolder();
holder.textView = (TextView) row.findViewById(R.id.exercise_list_text_view);
holder.imageView = (ImageView) row.findViewById(R.id.trash_button);
holder.editText = (EditText) row.findViewById(R.id.exercise_list_edit_text_view);
holder.deleteButton = (Button) row.findViewById(R.id.delete_button);

row.setTag(holder);

} else {
holder = (ExerciseListHolder) row.getTag();
}

final Exercise exercise = data.get(position);
holder.textView.setText(exercise.getName());
holder.imageView.setVisibility(View.GONE);
holder.editText.setVisibility(View.GONE);
holder.deleteButton.setVisibility(View.GONE);

holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.imageView.setVisibility(View.GONE);
holder.deleteButton.setVisibility(View.VISIBLE);
holder.deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Database db = new Database(context);
db.deleteExercise(exercise);
notifyDataSetChanged();

}
});

}
});
row.setFocusable(true);

row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.requestFocus();

Log.d("focused?", Boolean.toString(v.isFocusable()));
Log.d("focused?", Boolean.toString(v.isFocused()));

ExerciseListHolder holder = (ExerciseListHolder) v.getTag();

holder.editText.setText(holder.textView.getText());
holder.editText.setSelection(holder.editText.getText().length());

holder.imageView.setVisibility(View.VISIBLE);
holder.textView.setVisibility(View.GONE);
holder.editText.setVisibility(View.VISIBLE);

}
});


return row;
}

最佳答案

也许添加到 ListView android:descendantFocusability="afterDescendants"可以帮助你。更多文档:here

关于Android listview 项目没有获得焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26664711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com