更新列表视图?
Update 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);
}
一旦您修改了该适配器中的数据,您需要对该适配器对象调用 notifyDataSetChanged()
。
来源:How to refresh Android listview?
还有:
Android ListView not refreshing after notifyDataSetChanged
使用这个
myListView.invalidateViews(); in on Resume method, this will help to create view Again in listview android. Or also Call notifyDataSetChanged();
on your Adapter
希望这会有所帮助
如何更新我的列表视图,每次我将图像添加到 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);
}
一旦您修改了该适配器中的数据,您需要对该适配器对象调用 notifyDataSetChanged()
。
来源:How to refresh Android listview?
还有:
Android ListView not refreshing after notifyDataSetChanged
使用这个
myListView.invalidateViews(); in on Resume method, this will help to create view Again in listview android. Or also Call
notifyDataSetChanged();
on your Adapter
希望这会有所帮助