Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid file chooser not working
    primarykey
    data
    text
    <p>I am writing an <code>Android</code> file chooser program and when adding the details in <code>ListView</code>, the flow doesn't work perfectly. In the file <code>Uploadlist.java</code> I am sending the directory path to another class <code>filedetails</code> that extends <code>ArrayAdapter</code>. But the code flow doesn't get into the method <code>getView()</code>. Can some tell the reason and tell why the code doesn't get into <code>getView()</code>. I have used the below code.</p> <p><strong>UploadList.Java</strong></p> <pre><code>public class UploadList extends ListActivity { private List&lt;String&gt; item=null; private List&lt;String&gt; path=null; private String root; private TextView mypath; String pathname,filename; ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mypath=(TextView)findViewById(R.id.path); image=(ImageView)findViewById(R.id.imageView1); root=Environment.getExternalStorageDirectory().getPath(); filedetails details=new filedetails(this, root); setListAdapter(details); } /** * @param dirPath */ public void getDir(String dirPath){ mypath.setText("Location is:"+dirPath); pathname=dirPath; filedetails details=new filedetails(this, dirPath); setListAdapter(details); } protected void onListItemClick(ListView l,View v,int position,long id){ File file=new File(path.get(position)); if(file.isDirectory()){ if(file.canRead()) getDir(path.get(position)); } else { filename=file.getName(); pathname=pathname+"/"+filename; Intent back=new Intent(this,Upload.class); Bundle filen=new Bundle(); filen.putString("filepath",pathname); back.putExtras(filen); startActivity(back); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_upload_list, menu); return true; } } </code></pre> <p><strong>filedetails.java</strong></p> <pre><code>public class filedetails extends ArrayAdapter&lt;String&gt; { Context context; File[]values; String dirPath; String root=Environment.getExternalStorageDirectory().getPath(); String filename; private List&lt;String&gt; item; private List&lt;String&gt; path; public filedetails(Context context,String dirPath) { super(context,R.layout.row1); this.context=context; this.dirPath=dirPath; } static class ViewHolder { public TextView text; public ImageView image; } public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.row1, parent, false); ViewHolder viewholder=new ViewHolder(); viewholder.text=(TextView)rowView.findViewById(R.id.textView1); viewholder.image=(ImageView)rowView.findViewById(R.id.imageView1); rowView.setTag(viewholder); item=new ArrayList&lt;String&gt;(); path=new ArrayList&lt;String&gt;(); File file=new File(dirPath); File[]filelist=file.listFiles(); ViewHolder holder=(ViewHolder)rowView.getTag(); if(!dirPath.equals(root)){ item.add(root); path.add(root); item.add("../"); path.add(file.getParent()); } for(int i=0;i&lt;filelist.length;i++){ File file1=values[i]; if(file1.canRead()) { if(file1.isDirectory()){ holder.image.setImageResource(R.drawable.folder); holder.text.setText(file1.getName()); } } else{ holder.image.setImageResource(R.drawable.file); holder.text.setText(file1.getName()); } } return rowView; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload