我在这个问题上需要一些帮助,我有listview包含播放/停止图像和textView的行,如果我按播放图像播放声音并更改图标停止图像和反向如果我按行本身做的相同的事情,但问题是当我按下行时图像改变它没关系,但如果按下一行的图像本身更改所选行中的图像但不反转所选行的图像,我想反转无论何时按(行或图像)
,每次单击列表视图图像 Set Sourcewb = ActiveWorkbook
' Create path and name for export
PathName = ThisWorkbook.Path & "_export"
' Copy the sheets so they don't get removed in the main file
Sheets(Array(1, 2)).Copy Before:=Sheets(1)
' Move the first two sheets to a new workbook
Sheets(Array(1, 2)).Move
' Save the active duplicated workbook
ActiveWorkbook.SaveAs Filename:=PathName, FileFormat:=Sourcewb.FileFormat
' Close the active duplicated workbook
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
}
enter code here azkar = (ListView) findViewById(R.id.add_playlist_listView);
adapter = new SoundsAdapter(this, playlists,azkar);
adapter.setCustomButtonListner(SoundsActivity.this);
azkar.setAdapter(adapter);
int lastPosition =-1;
azkar.setOnItemClickListener(new AdapterView.OnItemClickListener() {
int pos;
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
adapter.getView(position, view, parent);
try {
if (lastPosition != -1) {
View lastRow = azkar.getChildAt(lastPosition);
ImageView play = (ImageView) lastRow.findViewById(R.id.is_added);
play.setImageResource(R.drawable.play_background);
View currentRow = azkar.getChildAt(position);
ImageView stop = (ImageView) currentRow.findViewById(R.id.is_added);
stop.setImageResource(R.drawable.stop_background);
}
lastPosition = position;
} catch (Exception e) {
}
final HashMap<String, String> committee = playlists.get(position);
String fileName = committee.get(CategoriesActivity.KEY_PATH);
run(committee.get(CategoriesActivity.KEY_PATH), view, position);
}
});
enter code here
@Override
public void onButtonClickListner(int position,View view,ViewGroup parent) {
Toast.makeText(getApplicationContext(), "aaaaaaa", Toast.LENGTH_LONG).show();
final int pos = position;
adapter.getView(position, view, parent);
try {
if (last != -1) {
View currentRow = azkar.getChildAt(position);
ImageView stop = (ImageView) currentRow.findViewById(R.id.is_added);
stop.setImageResource(R.drawable.stop_background);
View lastRow = azkar.getChildAt(last);
ImageView play = (ImageView) lastRow.findViewById(R.id.is_added);
play.setImageResource(R.drawable.play_background);
} else {
View currentRow = azkar.getChildAt(position);
ImageView stop = (ImageView) currentRow.findViewById(R.id.is_added);
stop.setImageResource(R.drawable.stop_background);
}
last = position;
}catch (Exception e){}
final HashMap<String, String> committee = playlists.get(position);
String fileName = committee.get(CategoriesActivity.KEY_PATH);
run(fileName, view, position);
答案 0 :(得分:0)
预期更改尝试此操作并尝试根据您的要求进行自定义。我在listview中有5个项目。并且listView.setOnItemClickListener
运行良好。更改您点击的唯一位置和休息视图将自动更新。
我不能做得更远。
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
View v;
int count =5; //parent.getChildCount();
v = parent.getChildAt(position);
parent.requestChildFocus(v, view);
ImageView imageView = (ImageView) v.findViewById(R.id.buttonPlayPause);
imageView.setImageResource(android.R.drawable.ic_media_pause);
int i=0;
while ( i < count) {
if (i != position) {
v = parent.getChildAt(i);
ImageView imageView1 = (ImageView) v.findViewById(R.id.buttonPlayPause);
imageView1.setImageResource(android.R.drawable.ic_media_play);
}
i++;
}
}
});