我和之前的帖子有同样的问题: ListFragment OnListItemClick not being called
但它的解决方案对我不起作用......我的东西没有焦点,仍然没有收到 ListFragment 的点击事件。很奇怪,因为如果我将 onclicklisteners 放在他们确实收到事件的项目上
我解释。我得到了这个 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,因为如果它在那里,它可以工作,但如果它不存在,则片段没有收到点击
我也发布了项目布局,所以你看到它是不可聚焦的,这是以前的解决方案......
<?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>
我现在能做什么?
任何帮助将不胜感激!