我遇到与上一篇文章相同的问题: ListFragment OnListItemClick not being called
但是它的解决方案对我不起作用......我的东西无法集中精力,仍然没有收到ListFragment的点击事件。很奇怪,因为如果我把onclicklistener放在他们收到事件的项目上
我解释一下。 我得到了这个ListFragment:
public class VideosListFragment extends ListFragment {
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Video item = (Video) getListAdapter().getItem(position);
DetailFragment fragment = (DetailFragment) getFragmentManager()
.findFragmentById(R.id.youtube_fragment);
if (fragment != null && fragment.isInLayout()) {
MainActivity videoParent = (MainActivity)getActivity();
videoParent.setVideo(item);
fragment.initialize(DeveloperKey.DEVELOPER_KEY, videoParent);
} else {
Intent intent = new Intent(getActivity().getApplicationContext(),
VideoPlayerActivity.class);
intent.putExtra(Video.VIDEO_ID, item.getVideoId());
startActivity(intent);
}
}
}
在其中我把这个ListAdapter:
public class VideosAdapter extends BaseAdapter implements ListAdapter{
// The list of videos to display
List<Video> videos;
// An inflator to use when creating rows
private LayoutInflater mInflater;
private Context context;
/**
* @param context this is the context that the list will be shown in - used to create new list rows
* @param videos this is a list of videos to display
*/
public VideosAdapter(Context _context, List<Video> _videos) {
this.videos = _videos;
this.context = _context;
this.mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return videos.size();
}
@Override
public Object getItem(int position) {
return videos.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = mInflater.inflate(R.layout.list_item_user_video, null);
}
UrlImageView thumb = (UrlImageView) convertView.findViewById(R.id.userVideoThumbImageView);
TextView title = (TextView) convertView.findViewById(R.id.userVideoTitleTextView);
Video video = videos.get(position);
// Set the image for the list item
thumb.setImageDrawable(video.getThumbUrl());
// Set the title for the list item
title.setText(video.getTitle());
// Bundle extra = new Bundle();
// extra.putString(Video.VIDEO_ID, video.getVideoId());
// convertView.setOnClickListener(new OnClickListenerExtra(context, VideoPlayerActivity.class, extra));
return convertView;
}
}
最后评论的每个项目都有一个Intent,因为如果它存在,它可以工作,但如果不存在,则片段没有收到点击
我发布了Item布局,所以你看它不可聚焦,这是以前的解决方案......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<com.vivoenmimundo.sc2hotsepicreplays.ui.widget.UrlImageView
android:id="@+id/userVideoThumbImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:contentDescription="YouTube video thumbnail"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/userVideoTitleTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:text="Video Title Not Found" />
</LinearLayout>
我现在能做什么?
任何帮助都将深表感谢!
答案 0 :(得分:3)
设置LinearLayout
android:clickable="false"