我有一个list view
个按钮,其中每一行都有播放按钮。如果我点击第一个播放按钮它会改变暂停,但如果我按下第二行播放按钮,那么首先将保持暂停状态,但我想如果按下任何一个按钮,那么前一个回到它的播放饱和按钮和点击的按钮更改暂停。请帮忙
if (position == mPlayingPosition&&equals(subscription_type_user)) {
textview_duration_Current.post(mUpdateTime);
//pb.setVisibility(View.VISIBLE);
Log.d("helyaa", String.valueOf(position));
mProgressUpdater.mBarToUpdate = pb;
mHandler.postDelayed(mProgressUpdater, 100);
} else {
Log.d("helnaa", String.valueOf(position));
//pb.setVisibility(View.GONE);
pb.setProgress(0);
textview_duration_Current.setText("");
if (mProgressUpdater.mBarToUpdate == pb) {
//this progress would be updated, but this is the wrong position
mProgressUpdater.mBarToUpdate = null;
}
我的列表点击活动
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View item,
int position, long id) {
Planet planet = listAdapter.getItem(position);
planet.toggleChecked();
PlanetViewHolder viewHolder = (PlanetViewHolder) item.getTag();
// viewHolder.getCheckBox().setChecked( planet.isChecked() );
if (planet.isChecked()) {
Toast.makeText(Main_New.this, "Play", Toast.LENGTH_SHORT).show();
//start playing item at position
try {
mPlayer.reset();
mPlayer.setDataSource(String.valueOf(planet = listAdapter.getItem(position)));
mPlayer.prepare();
mPlayer.start();
//mPlayingPosition = position;
Log.d("OnlyPos", String.valueOf(position));
// Log.d("Postionof", String.valueOf(mPlayingPosition));
//Toast.makeText(this,"Position of"+mPlayingPosition,Toast.LENGTH_SHORT).show();
// Updating progress bar
//updateProgressBar();
//trigger list refresh, this will make progressbar start updating if visible
} catch (IOException e) {
// Log.e( "unable to play: " + planetList.get(position));
e.printStackTrace();
}
}
;
}
});
答案 0 :(得分:2)
试试这个
保留名为position
#Capture logs from user defined packages (by default logs captured only from "com.worklight" package)
wl.analytics.logs.packages=my.package.com
方法中的检查位置
BasicFileAttributes
getView()
更新该变量位置;并执行if (position == selectedPosition) {
// change the button color or whatever
} else {
// keep things in the normal way
}
调用setOnItemClickListener
方法
完成!
答案 1 :(得分:1)
设置listView父radioGroup并使用播放/暂停的自定义可绘制图像设置radioButton,如: drawable_state.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pause" android:state_checked="false" android:state_focused="true"/>
<item android:drawable="@drawable/pause" android:state_checked="false" android:state_focused="false"/>
<item android:drawable="@drawable/play" android:state_checked="true" android:state_focused="true"/>
<item android:drawable="@drawable/play" android:state_checked="true" android:state_focused="false"/>
</selector>
在radioButton标记
中设置此样式属性<style name="radionbutton"
parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">@drawable/drawable_state</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
这将解决你的问题