2

How can i update my listview, every time i add images to sdcard it's not showing I need to run my app again to see the pictures. Can you please help me thanks.

@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);

}
JAC
  • 119
  • 12
  • call `notifyDataSetChanged()` to refresh your list after updating the data that populates your list. – Raghunandan Jan 14 '15 at 04:52
  • I try to put it "frameChooserAdapter.notifyDataSetChanged();" but it's not working. – JAC Jan 14 '15 at 06:27
  • where did you put that line of code? You need to update the data that populates list then refresh listview – Raghunandan Jan 14 '15 at 06:27
  • i just put it in onCreate, i dont know where should i put . hehe – JAC Jan 14 '15 at 06:39
  • read activity lifecycle. onCreate is called once during the lifecycle of the activity until it is destroyed. So it is expected to work that way. you need to decide how you want to refresh. Study activity lifecycle – Raghunandan Jan 14 '15 at 06:40
  • possible duplicate of [How to refresh Android listview?](http://stackoverflow.com/questions/2250770/how-to-refresh-android-listview) – Lokesh Jan 18 '15 at 07:41

2 Answers2

1

You need to call notifyDataSetChanged() on your Adapter object once you've modified the data in that adapter.

Source : How to refresh Android listview?

And also :

Android ListView not refreshing after notifyDataSetChanged

Community
  • 1
  • 1
Pihu
  • 1,041
  • 11
  • 35
1

Use this

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

Hope this will help

Sukhbir
  • 1,410
  • 14
  • 33