2
我是一個android開發noob,我想做一個listview,每行有一個VideoView。我希望VideoView一旦行焦點就開始播放,當行失焦時停止播放,類似於Instagram的做法。按照post的建議,我已在我的適配器類的getView方法內的View上設置了OnFocusChangeListener。但是,OnFocusChange方法似乎永遠不會被調用。我怎樣才能確定哪個ListView行是焦點?任何幫助解決這個問題都非常感謝。如何確定ListView行是否集中?
我的代碼
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
song = new HashMap<String, String>();
ViewHolder holder;
if(convertView==null){
holder = new ViewHolder();
vi = inflater.inflate(R.layout.allmedialist_row, null);
holder.clubname = (TextView)vi.findViewById(R.id.clubname); // title
holder.dates = (TextView)vi.findViewById(R.id.artist); // artist name
holder.vidimg=(ImageView)vi.findViewById(R.id.list_image);
holder.clubimg =(ImageView)vi.findViewById(R.id.clubimg); // thumb image
holder.playimg =(ImageView)vi.findViewById(R.id.playimg); // thumb image
holder.username = (TextView)vi.findViewById(R.id.username); // artist name
holder.video_screen = (VideoView)vi.findViewById(R.id.VideoView1); // artist name
holder.header = (RelativeLayout)vi.findViewById(R.id.header);
holder.header.setVisibility(View.GONE);
holder.video_screen.setTag(position);
holder.username.setTag(position);
vi.setTag(holder);
// vi.setFocusable(true);
// vi.setFocusableInTouchMode(true);
} else {
holder = (ViewHolder) vi.getTag();
}
song = data.get(position);
vi.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
Log.e("HAS FOCUS", "true");
}else {
Log.e("NO FOCUS", "true");
}
}
});
vi.setFocusableInTouchMode(true);
return vi;
}
你的意思是在日誌中只顯示NO FOCUS顯示不是HAS FOCUS? – 2014-11-14 15:39:35
@MohammedAli既不顯示日誌消息。 – DollaBill 2014-11-14 15:46:06
意味着OnFocusChangeListener()不被調用? – 2014-11-14 15:47:37