Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更新列表视图?_Android_Image_Listview - Fatal编程技术网

Android 更新列表视图?

Android 更新列表视图?,android,image,listview,Android,Image,Listview,如何更新我的listview,每次我向SD卡添加图像时,它都不会显示我需要再次运行我的应用程序才能看到图片。你能帮我吗?谢谢 @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.acmain); s

如何更新我的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);

}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.acmain);
SharedReferences=this.getSharedReferences(MyPREFERENCES,
上下文。模式(私人);
frameChooserGV=(ListView)findViewById(R.id.ListView);
utils=新的UtilsList(ListViewImage.this.getApplicationContext());
初始化egridlayout();
framepath=utils.getFilePath();
FrameChooseAdapter=新建ListViewImageAdapter(
ListViewImage.this.getApplicationContext(),帧路径,
柱宽);
FrameChooseAdapter.notifyDataSetChanged();
FrameChooseGV.setAdapter(FrameChooseAdapter);
frameChooserGV.setOnItemClickListener(此);
}
public void初始化egridlayout(){
Resources r=getResources();
浮动填充=TypedValue.applyDimension(TypedValue.COMPLEX\u UNIT\u DIP,
AppConstant.GRID_PADDING,r.getDisplayMetrics();
columnWidth=(int)((utils.getScreenWidth()-((AppConstant.NUM_OF_COLUMNS+1)*padding))/AppConstant.NUM_OF_COLUMNS);
}
@凌驾
public void onItemClick(AdapterView父视图、视图、整型位置、,
长id){
//TODO自动生成的方法存根
Log.e(“+frameChooserGV.getPositionForView(视图),”+position);
意图b_Intent=新意图(getApplicationContext(),
com.example.customize.customizeEnumberDisplay.class);
b_意向额外(“位置”,位置);
星触觉(b_意向);
}

修改适配器中的数据后,需要在适配器对象上调用
notifyDataSetChanged()

资料来源:

而且:

使用这个

myListView.invalidateViews();在on Resume方法中,这将有助于在listview android中再次创建视图。或者也可以调用
notifyDataSetChanged()


希望这将有助于在更新填充列表的数据后调用
notifyDataSetChanged()
刷新列表。我尝试将其设置为“FrameChooseAdapter.notifyDataSetChanged();”,但它不起作用。您将这行代码放在哪里了?你需要更新填充列表的数据,然后刷新列表视图。我只是把它放在onCreate中,我不知道应该放在哪里。heheread活动生命周期。onCreate在活动的生命周期中调用一次,直到它被销毁。因此,预计它将以这种方式工作。您需要决定如何刷新。学习活动生命周期