【发布时间】:2015-01-14 04:50:17
【问题描述】:
如何更新我的列表视图,每次我将图像添加到 sdcard 时,它都没有显示我需要再次运行我的应用程序才能看到图片。你能帮我吗谢谢。
@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()以在更新填充列表的数据后刷新您的列表。 -
我试着把它写成“frameChooserAdapter.notifyDataSetChanged();”但它不起作用。
-
你把那行代码放在哪里了?您需要更新填充列表的数据,然后刷新列表视图
-
我只是把它放在 onCreate 中,我不知道我应该把它放在哪里。呵呵
-
读取活动生命周期。 onCreate 在活动的生命周期中被调用一次,直到它被销毁。所以预计它会以这种方式工作。您需要决定如何刷新。学习活动生命周期