gpt4 book ai didi

android - 如何获取在android中单击的Listview项的值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:51 26 4
gpt4 key购买 nike

我有下面的代码将 ListView 项目值访问到字符串中并在警报中显示它吗?

ListView shot = getListView();
shot.setOnItemClickListener(this);

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

String S = arg1.getContext().toString();
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

// set the message to display
alertbox.setMessage(S).show();
}

最佳答案

也许这个例子对你有帮助

  lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});

https://developer.android.com/reference/android/widget/ListView.html

关于android - 如何获取在android中单击的Listview项的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2988378/

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