gpt4 book ai didi

android - 更新 ListView ?

转载 作者:行者123 更新时间:2023-11-29 00:14:04 25 4
gpt4 key购买 nike

如何更新我的 ListView ,每次我将图像添加到 SD 卡时它都没有显示我需要再次运行我的应用程序才能看到这些图片。你能帮帮我吗,谢谢。

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.acmain);

sharedpreferences = this.getSharedPreferences(MyPREFERENCES,
Context.MODE_PRIVATE);
frameChooserGV = (ListView) findViewById(R.id.listview);
utils = new UtilsList(ListViewImage.this.getApplicationContext());
InitializeGridLayout();
framePaths = utils.getFilePaths();
frameChooserAdapter = new ListViewImageAdapter(
ListViewImage.this.getApplicationContext(), framePaths,
columnWidth);
frameChooserAdapter.notifyDataSetChanged();
frameChooserGV.setAdapter(frameChooserAdapter);
frameChooserGV.setOnItemClickListener(this);
}

public void InitializeGridLayout() {
Resources r = getResources();
float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
AppConstant.GRID_PADDING, r.getDisplayMetrics());
columnWidth = (int) ((utils.getScreenWidth() - ((AppConstant.NUM_OF_COLUMNS + 1) * padding)) / AppConstant.NUM_OF_COLUMNS);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
Log.e("" + frameChooserGV.getPositionForView(view), "" + position);
Intent b_intent = new Intent(getApplicationContext(),
com.example.customize.CustomizeNumberDisplay.class);
b_intent.putExtra("position", position);
startActivity(b_intent);

}

最佳答案

使用这个

myListView.invalidateViews(); in on Resume method, this will help to create view Again in listview android. Or also Call notifyDataSetChanged(); on your Adapter

希望对你有帮助

关于android - 更新 ListView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27936073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com