When I click on item its icon is change. But moreover some other icons change. Every 9 or 10 icon is change. Looks like I change icon on every "screen". I don't understand why for 4 days. Please, help.
https://i.stack.imgur.com/oBIew.png
https://i.stack.imgur.com/N8qna.png
Here my ListView in activity_main.xml:
<ListView
android:id= "@+id/lvSimple"
android:layout_width= "fill_parent"
android:layout_height= "wrap_content"
android:paddingTop= "8dp"
android:paddingBottom= "8dp"
android:paddingLeft= "0dp"
android:paddingRight= "0dp"
android:divider= "@null"
android:dividerHeight= "0dp"
android:choiceMode="multipleChoice"
android:descendantFocusability= "blocksDescendants">
</ListView>
list_view_item.xml
<?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="56dp"
android:orientation="horizontal"
android:padding="0dp"
android:background="@drawable/change_color_on_press"
android:checkable="true"
android:id="@+id/item">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/icon">
<ImageView
android:id="@+id/iconFront"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:src="@drawable/ic_folder_white_grey600_36dp">
</ImageView>
<ImageView
android:id="@+id/iconBack"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:gravity="center"
android:alpha="0"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:src="@drawable/ic_check_circle_grey600_white_36dp">
</ImageView>
</FrameLayout>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:gravity="start"
android:paddingTop="16dp"
android:paddingLeft="0dp"
android:paddingRight="32dp"
android:textSize="16sp"
android:text="TextView">
</TextView>
</LinearLayout>
MainActivity.java
...
lvSimple = (ListView) findViewById(R.id.lvSimple);
sAdapter = createSimpleAdapter(readFolder(current_folder));
lvSimple.setAdapter(sAdapter);
...
lvSimple.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
ImageView child1_img = (ImageView) view.findViewById(R.id.iconFront);
ImageView child2_img = (ImageView) view.findViewById(R.id.iconBack);
final AnimatorSet setLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(getApplicationContext(),
R.animator.flip_left_in);
final AnimatorSet setLeftOut = (AnimatorSet) AnimatorInflater.loadAnimator(getApplicationContext(),
R.animator.flip_left_out);
if(lvSimple.isItemChecked(position)){
setLeftOut.setTarget(child1_img);
setLeftIn.setTarget(child2_img);
setLeftOut.start();
setLeftIn.start();
lvSimple.setItemChecked(position, true);
}
else{
setLeftOut.setTarget(child2_img);
setLeftIn.setTarget(child1_img);
setLeftOut.start();
setLeftIn.start();
lvSimple.setItemChecked(position, false);
}
}
});
...
public String[] readFolder(String path) {
try {
if ((new File(path)).isDirectory()) {
File file = new File(path);
File[] files = file.listFiles();
ArrayList<String> file_names = new ArrayList<String>();
ArrayList<String> dir_names = new ArrayList<String>();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) dir_names.add(files[i].getName());
else file_names.add(files[i].getName());
}
Collections.sort(dir_names);
Collections.sort(file_names);
String[] texts = new String[dir_names.size() + file_names.size()];
int count = 0;
for (int i = 0; i < dir_names.size(); i++) {
texts[count] = dir_names.get(i);
count++;
}
for (int i = 0; i < file_names.size(); i++) {
texts[count] = file_names.get(i);
count++;
}
if (texts.length == 0) {
list_view_error = true;
sToast("Directory is empty");
}
return texts;
}
else {
sToast("It's file");
list_view_error = true;
return (new String[0]);
}
} catch (Exception e) {
sToast("Directory is empty");
list_view_error = true;
return (new String[0]);
}
}
public SimpleAdapter createSimpleAdapter(String[] texts) {
data = new ArrayList<Map<String, Object>>(texts.length);
for (int i = 0; i < texts.length; i++) {
m = new HashMap<String, Object>();
m.put(ATTRIBUTE_NAME_TEXT, texts[i]);
if ((new File(current_folder + texts[i])).isDirectory())
m.put(ATTRIBUTE_NAME_IMAGE, img_folder);
else m.put(ATTRIBUTE_NAME_IMAGE, img_file);
data.add(m);
}
String[] from = {ATTRIBUTE_NAME_TEXT, ATTRIBUTE_NAME_IMAGE};
int[] to = {R.id.text, R.id.iconFront};
return new SimpleAdapter(this, data, R.layout.list_view_item, from, to);
}