gpt4 book ai didi

android - 如何在自定义 ListView 中将特定 TextView 文本显示为 toast 消息?

转载 作者:行者123 更新时间:2023-11-30 01:21:24 25 4
gpt4 key购买 nike

我有一个自定义 ListView ,每一行都有 3 个 TextView 这是我的自定义 ListView 适配器。如何在自定义 ListView 中将特定 TextView 文本显示为 toast 消息,以及如何在另一个 Activity 中发送该文本?

细节是我的getter和setter类

public class CustomListViewAdapter extends ArrayAdapter<Details> {

Context context;


public CustomListViewAdapter(Context context, int resourceId,
List<Details> items) {
super(context, resourceId, items);
this.context = context;
}



/*private view holder class*/
private class ViewHolder {
//ImageView textView;
TextView txtTitle;
TextView txtTitle2;
TextView txtDesc;
}

@SuppressLint("InflateParams")
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
//Details rowItem = (Details) getItem(position);
Details rowItem = getItem(position);
context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

if (convertView == null || convertView.getTag() == null) {

LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.list_item, null); //TODO: parent instead of null?

holder = new ViewHolder();

holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.txtTitle2 = (TextView) convertView.findViewById(R.id.link);
convertView.setTag(holder);


}

else if (rowItem.getResType().equals(vid)){

holder = (ViewHolder) convertView.getTag();
}
if (holder != null) {
holder.txtDesc.setText(rowItem.getResType());
holder.txtTitle.setText(rowItem.getName());

holder.txtTitle2.setText(rowItem.getUrl());

}

return convertView;
}

}

最佳答案

您可以在您的自定义适配器中Override TextViewOnClick 方法,并根据该方法在您的Toast 中显示文本 如下所示

txttitle.setOnClickListener(new View.OnClickListener() {
@覆盖
public void onClick(View v) {
Toast.makeText(getActivity(),
“点击 ListItem Number” + txttitle.getText().toString(), Toast.LENGTH_LONG)
。展示();
}
});

关于android - 如何在自定义 ListView 中将特定 TextView 文本显示为 toast 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37049661/

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