Android ths; } 类ViewContainer{ 公共影像视图; 公共文本视图txtPath; } @凌驾 公共视图getView(内部位置、视图视图、视图组父视图){ 视图容器视图容器; 视图行视图=视图; 位图无标度位图; 位图缩放位图; if(rowView==null){ LayoutInflater充气器=上下文。getLayoutInflater(); rowView=充气器。充气(R.layout.list\u位图\u路径,空, 正确的); viewContainer=新的viewContainer(); viewContainer.txtPath=(TextView)行视图 .findviewbyd(R.id.imagePath); viewContainer.imageView=(imageView)行视图 .findviewbyd(R.id.icon); setTag(viewContainer); }否则{ viewContainer=(viewContainer)rowView.getTag(); } viewContainer.txtPath.setText(this.path.get(position)); viewContainer.imageView.setImageBitmap(空); unscaledBitmap=scalinguities.decode文件( this.path.get(position)、100100、ScalingLogic.FIT); scaledBitmap=ScalingUtilities.createScaledBitmap(unscaledBitmap, 100,100,ScalingLogic.FIT); viewContainer.imageView.setImageBitmap(缩放位图); 如果(位置%2==0){ setBackgroundColor(Color.rgb(238233233)); }否则{ setBackgroundColor(Color.rgb(255、255、255)); } 返回行视图; } }
}您可以从实际的ListView中删除AllView(),而不仅仅是清除适配器。。。试一试Android ths; } 类ViewContainer{ 公共影像视图; 公共文本视图txtPath; } @凌驾 公共视图getView(内部位置、视图视图、视图组父视图){ 视图容器视图容器; 视图行视图=视图; 位图无标度位图; 位图缩放位图; if(rowView==null){ LayoutInflater充气器=上下文。getLayoutInflater(); rowView=充气器。充气(R.layout.list\u位图\u路径,空, 正确的); viewContainer=新的viewContainer(); viewContainer.txtPath=(TextView)行视图 .findviewbyd(R.id.imagePath); viewContainer.imageView=(imageView)行视图 .findviewbyd(R.id.icon); setTag(viewContainer); }否则{ viewContainer=(viewContainer)rowView.getTag(); } viewContainer.txtPath.setText(this.path.get(position)); viewContainer.imageView.setImageBitmap(空); unscaledBitmap=scalinguities.decode文件( this.path.get(position)、100100、ScalingLogic.FIT); scaledBitmap=ScalingUtilities.createScaledBitmap(unscaledBitmap, 100,100,ScalingLogic.FIT); viewContainer.imageView.setImageBitmap(缩放位图); 如果(位置%2==0){ setBackgroundColor(Color.rgb(238233233)); }否则{ setBackgroundColor(Color.rgb(255、255、255)); } 返回行视图; } },android,arrays,listview,android-listview,android-fragments,Android,Arrays,Listview,Android Listview,Android Fragments,}您可以从实际的ListView中删除AllView(),而不仅仅是清除适配器。。。试一试 ((ListBitmapsFragment)fragment).getListView().removeAllViews() 多亏了Atomix,我找到了这个问题的解决方案——在方法callTheFragment()中,我做了一些更改:我在容器中使用了关于片段的信息,并在该信息之后删除了它,如果该片段已经退出的话,同时我在片段中找到了视图组(容器),并清除了它的所有视图。它是有效的。 谢谢 埃里克D 您
((ListBitmapsFragment)fragment).getListView().removeAllViews()
多亏了Atomix,我找到了这个问题的解决方案——在方法callTheFragment()中,我做了一些更改:我在容器中使用了关于片段的信息,并在该信息之后删除了它,如果该片段已经退出的话,同时我在片段中找到了视图组(容器),并清除了它的所有视图。它是有效的。 谢谢 埃里克D
您好,Atomix,我将尝试发布反馈。此方法不受支持,调用时抛出UnsupportedOperationException。
public class ListBitmapsFragment extends ListFragment {
private Callbacks mCallbacks;
public interface Callbacks {
public void onBitmapSelected(String path);
}
private static Callbacks sDummyCallbacks = new Callbacks() {
@Override
public void onBitmapSelected(String imagePath) {
}
};
public ListBitmapsFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new CustomAdapter(getActivity(), pathArray()));
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (!(activity instanceof Callbacks)) {
throw new IllegalStateException(
"Klicoca aktivnost mora implementirati callback!!");
}
mCallbacks = (Callbacks) activity;
}
@Override
public void onDetach() {
super.onDetach();
mCallbacks = sDummyCallbacks;
}
@Override
public void onListItemClick(ListView listView, View view, int position,
long id) {
super.onListItemClick(listView, view, position, id);
View row = view;
TextView tv = (TextView) row.findViewById(R.id.imagePath);
mCallbacks.onBitmapSelected(tv.getText().toString());
}
private List<String> pathArray() {
String rootPath = getArguments().getString("pathValue");
final List<String> directoryEntries = new ArrayList<String>();
File directory = new File(rootPath);
if (directory.isDirectory()) {
File[] files = directory.listFiles();
Arrays.sort(files, new Comparator<File>() {
public int compare(File f1, File f2) {
return -Long.valueOf(f1.lastModified()).compareTo(
f2.lastModified());
}
});
directoryEntries.clear();
for (File file : files) {
directoryEntries.add(file.getPath());
}
}
if (directoryEntries.isEmpty()) {
directoryEntries.add("storage/extSdCard/DCIM/Camera/no_photo.jpg");
}
return directoryEntries;
}
class CustomAdapter extends ArrayAdapter<String> {
private final Activity context;
private final List<String> paths;
public CustomAdapter(Activity context, List<String> paths) {
super(context, R.layout.list_bitmap_paths, paths);
this.context = context;
this.paths = paths;
}
class ViewContainer {
public ImageView imageView;
public TextView txtPath;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewContainer viewContainer;
View rowView = view;
Bitmap unscaledBitmap;
Bitmap scaledBitmap;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.list_bitmap_paths, null,
true);
viewContainer = new ViewContainer();
viewContainer.txtPath = (TextView) rowView
.findViewById(R.id.imagePath);
viewContainer.imageView = (ImageView) rowView
.findViewById(R.id.icon);
rowView.setTag(viewContainer);
} else {
viewContainer = (ViewContainer) rowView.getTag();
}
viewContainer.txtPath.setText(this.paths.get(position));
viewContainer.imageView.setImageBitmap(null);
unscaledBitmap = ScalingUtilities.decodeFile(
this.paths.get(position), 100, 100, ScalingLogic.FIT);
scaledBitmap = ScalingUtilities.createScaledBitmap(unscaledBitmap,
100, 100, ScalingLogic.FIT);
viewContainer.imageView.setImageBitmap(scaledBitmap);
if (position % 2 == 0) {
rowView.setBackgroundColor(Color.rgb(238, 233, 233));
} else {
rowView.setBackgroundColor(Color.rgb(255, 255, 255));
}
return rowView;
}
}
((ListBitmapsFragment)fragment).getListView().removeAllViews()
public void callTheFragment(String pathValue) {
// set the object for the fragment manager
FragmentManager fm = getSupportFragmentManager();
// set object of the fragment class - container for the fragment
Fragment fragment = fm.findFragmentById(R.id.item_list);
// if there is a fragment allready in the container
if (!(fragment == null)) {
// remove the existing fragment
fm.beginTransaction().remove(fragment).commit();
// get reference to the parrent container
ViewGroup vg = (ViewGroup) findViewById(R.id.item_list);
// delete all views from the parrent container
vg.removeAllViews();
}
// new fragment
// object of variables for pass them to the fragment
Bundle args = new Bundle();
args.putString("pathValue", pathValue);
// FragmentTransaction ft = fm.beginTransaction();
fragment = new ListBitmapsFragment();
// set the object of arguments to the new fragment
fragment.setArguments(args);
// execute transaction
fm.beginTransaction().add(R.id.item_list, fragment).commit();
}