【发布时间】:2016-04-02 03:06:11
【问题描述】:
我在这个问题上需要一些帮助,我有包含播放/停止图像和 textView 行的列表视图,如果我按下播放图像播放声音并将图标更改为停止图像和反转,如果我按下行本身执行同样的事情,但问题是当我按下行时图像改变它没关系但是如果按下下一行的图像本身改变所选行中的图像但不反转之前选择的行的图像,我想在每次点击时反转列表视图图像无论我按什么(行或图像)
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);
}
enter code here //code in adapter
thumb_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (customListner != null) {
customListner.onButtonClickListner(position, convertView, parent);
}
}
});
return vi;
}
public interface customButtonListener {
public void onButtonClickListner(int position,View view,ViewGroup parent);
}
public void setCustomButtonListner(customButtonListener listener) {
this.customListner = listener;
}
【问题讨论】:
-
您能发布您用于此行为的代码吗?
-
在按下每一行之前通知适配器数据集更改如下:notifyDataSetChanged():
-
请出示您的代码
-
this:notifyDataSetChanged(): not working,这个问题很难解释,但我尽力做到最好,当我在列表视图中按行本身并更改图像但按图像时出现问题本身在行中,而不是另一行列表视图的行本身,具有与先前选择的不同位置
-
你为什么不使用两个按钮。当按下另一个按钮时,设置一个按钮的可见性消失。
标签: android android-listview android-imageview onclicklistener onitemclicklistener