gpt4 book ai didi

android - 选择用于复制 Android EditText 的文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:00 24 4
gpt4 key购买 nike

我想在 EditText 中选择一些文本,它是 ListView 的子元素。所选文本必须设置在剪贴板上。我找不到任何关于此的例子。我该怎么办? selectionStart 和 selectionEnd 对此不起作用。谢谢。

最佳答案

这是可能的解决方案。在listview的getView方法中执行如下操作:

enter code here:

public View getView(final int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
final ViewHolder holder;


if (convertView == null) {
convertView = mInflater.inflate(R.layout.main, null);

// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();


holder.subText = (TextView) convertView.findViewById(R.id.subTxt);

convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}

//TEXT BOX position is 0 then
if(position == 0) {

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(txtEdit.getText().toString());
}
return convertView;
}

关于android - 选择用于复制 Android EditText 的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8608021/

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