android - Unable to attach file though after you are navigated to files using ACTION_GET_CONTENT -


import android.app.activity; import android.content.intent; import android.net.uri; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.button; import android.widget.listview; import java.util.arraylist;  public class attachfiles extends activity {      button btnaddfile;     listview listviewfiles;     string[] str;     arraylist<string> arraylist = new arraylist<string>();      adapter myfilelistadapter;     final int rqs_loadimage = 0;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          btnaddfile = (button) findviewbyid(r.id.addphoto);         btnaddfile.setonclicklistener(btnaddfileonclicklistener);      }      view.onclicklistener btnaddfileonclicklistener             = new view.onclicklistener() {          @override         public void onclick(view v) {              intent intent = new intent(intent.action_get_content);             intent.settype("file/*");             startactivityforresult(intent, rqs_loadimage);          }     };      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         // todo auto-generated method stub         super.onactivityresult(requestcode, resultcode, data);           if (resultcode == result_ok) {             switch (requestcode) {                 case rqs_loadimage:                     uri imageuri = data.getdata();                     string string = imageuri.tostring();                     log.e("string", " "+string);                      arraylist.add(string);                      log.e("get arraylist :" , " "+arraylist);                      myfilelistadapter = new adapter(attachfiles.this, arraylist);                     listviewfiles = (listview) findviewbyid(r.id.filelist);                     listviewfiles.setadapter(myfilelistadapter);                     myfilelistadapter.notifydatasetchanged();                     break;             }         }     } } 

in above code can see files couldn't load listview.

in case getting result inside onactivityresult().i haven't see other chance error. change adapter arrayadapter

arrayadapter< string > myfilelistadapter = new arrayadapter< string >(attachfiles.this, android.r.layout.simple_list_item_1, arraylist); 

and declaring listview inside oncreate better.

and give try :)


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -