I'm getting an error in eclipse stating: The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (String, TextView)
I believe I'll need to change my textView to a boolean however when I attempt to do so - it causes other errors to occur. What is the best way of avoiding this error in a scenario such as this:
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);
}
and in get view:
final Cmd cmd = (Cmd) getItem(position);
and in onclick:
run(cmd.getCmd());
The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (String, TextView)
public Intent putExtra (String name, boolean value)
name is the key and value is a boolean. So it expects a boolean value.
I don't think you want to boolean either. I guess you want to pass the text in textview to another activity
Look @
http://developer.android.com/reference/android/content/Intent.html
You can use the View
object v
holder.txtCmd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView tv =(TextView)v; // cast to textview
Intent intent = new Intent(context, ViewVideo.class);
intent.putExtra("videofilename", tv.getText().toString());
// use getText to get the text from textview
context.startActivity(intent);
}
});
Or you can use setTag
and getTag
on the view
The part:
ViewHolder holder;
intent.putExtra("videofilename", holder.txtCmd);
won't get you anything, holder.txtCmd.getText is not going to return the filename, instead you can pass the file name with the function run(String filename) as a parameter. Then you will be able to pass it directly as text.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.