我写下面的代码当我只使用thumbNail.setOnClickListener(新的View.OnClickListener()时,代码工作正常。只要我再添加一个方法,即vdownload.setOnClickListener(new View.OnClickListener(),它就开始给出NPE on vdownload.setOnClickListener(new View.OnClickListener()。为什么两者不能一起工作。
这是我的代码:
var c = a.match(/[a-zA-Z]/g);
console.log(c)
//output :(9) ["d", "a", "a", "d", "v", "a", "v", "d", "a"]
// this is the output i needed
这是错误日志:
public class YouTubeCustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater layoutInflater;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
private List<YouTubeMov> youTubeMov;
private int idgot;
public YouTubeCustomListAdapter(Activity activity, List<YouTubeMov> youTubeMovs, int id) {
this.activity = activity;
this.youTubeMov = youTubeMovs;
this.idgot = id;
}
@Override
public int getCount() {
return youTubeMov.size();
}
@Override
public Object getItem(int position) {
return youTubeMov.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
System.out.println("Launched");
if (layoutInflater == null) {
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if (convertView == null)
if (idgot == 1) {
convertView = layoutInflater.inflate(R.layout.youtubecustomlistmains, null);
} else {
convertView = layoutInflater.inflate(R.layout.youtubecustomlist, null);
}
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
NetworkImageView thumbNail = (NetworkImageView) convertView
.findViewById(R.id.thumbnail);
TextView title = (TextView) convertView.findViewById(R.id.titles);
TextView totalviews = (TextView) convertView.findViewById(R.id.totalviews);
TextView genre = (TextView) convertView.findViewById(R.id.genre);
TextView vdownload = (TextView) convertView.findViewById(R.id.vdownlay);
thumbNail.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
Popup.smallpopup("Text", activity);
YouTubeMov dm = youTubeMov.get(position);
String vid = dm.getId();
System.out.println(vid);
Intent intent = new Intent(activity, MyYouTube.class);
intent.putExtra("videoid", vid);
activity.startActivity(intent);
}
});
vdownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// code to Work
}
});
if (idgot == 1) {
movieId = (TextView) convertView.findViewById(R.id.movieid);
}
TextView duration = (TextView) convertView.findViewById(R.id.duration);
// getting movie data for the row
YouTubeMov tubeMov = youTubeMov.get(position);
// thumbnail image
thumbNail.setImageUrl(tubeMov.getThumbnailurl(), imageLoader);
// title
title.setText(tubeMov.getTitle());
System.out.println("Got Title " + tubeMov.getTitle());
// Total Views
totalviews.setText("Total Views: " + String.valueOf(tubeMov.getViews()));
// genre
genre.setText("Genre: " + String.valueOf(tubeMov.getChannel()));
// release year
/*if (idgot == 1) {
movieId.setText("Id: " + (tubeMov.getId()));
}
*/
duration.setText("Time: " + tubeMov.getDuration());
return convertView;
}
}