gpt4 book ai didi

java - 将 textView 转换为 Boolean 以避免类型 Intent 中的 : The method putExtra(String, boolean) 不适用于参数

转载 作者:行者123 更新时间:2023-12-02 06:13:25 25 4
gpt4 key购买 nike

我在 eclipse 中遇到错误,指出:Intent 类型中的方法 putExtra(String, boolean) 不适用于参数 (String, TextView)

我相信我需要将 textView 更改为 boolean 值,但是当我尝试这样做时 - 它会导致其他错误发生。在这种情况下避免此错误的最佳方法是什么:

public class CustomListViewAdapter extends ArrayAdapter<Cmd> {
Activity context;
List<Cmd> videos;

public CustomListViewAdapter(Activity context, List<Cmd> videos) {
super(context, R.layout.list_item2, videos);

this.context = context;
this.videos = videos;
}

/* private view holder class */
private class ViewHolder {
ImageView imageView;
TextView txtSuccess;
TextView txtCmd;
TextView txtPrice;
}

public void run() {

Intent intent = new Intent(context, ViewVideo.class);
ViewHolder holder;
intent.putExtra("videofilename", holder.txtCmd);
context.startActivity(intent);
}

public Cmd getItem(int position) {
return videos.get(position);
}

public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item2, null);
holder = new ViewHolder();
holder.txtSuccess = (TextView) convertView
.findViewById(R.id.success);
holder.txtCmd = (TextView) convertView.findViewById(R.id.cmd);
holder.txtPrice = (TextView) convertView.findViewById(R.id.price);
holder.imageView = (ImageView) convertView
.findViewById(R.id.thumbnail);
convertView.setTag(holder);

} else {
holder = (ViewHolder) convertView.getTag();
}

Cmd cmd = (Cmd) getItem(position);

holder.txtSuccess.setText(cmd.getVideoName());
holder.txtSuccess.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
run();
}
});
holder.txtCmd.setText(cmd.getCmd());
holder.txtCmd.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
run();
}
});

holder.txtPrice.setText(cmd.getVideoURL() + "");
holder.txtPrice.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
run();
}
});

holder.imageView.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
run();
}
});
return convertView;

}

}

最佳答案

public void run(String txt) {

Intent intent = new Intent(context, ViewVideo.class);
intent.putExtra("videofilename",txt);
context.startActivity(intent);
}

并在获取 View 中:

final  Cmd cmd = (Cmd) getItem(position);

并在onclick中:

run(cmd.getCmd());

关于java - 将 textView 转换为 Boolean 以避免类型 Intent 中的 : The method putExtra(String, boolean) 不适用于参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21682720/

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