android - Arraylist not working -


i have written code download contents on sdcard , trying list downloded contents have written code , working fine want 1 view button every item in list writing in rowmydownload.xml.when doing getting exception java.lang.illegalstateexception: arrayadapter requires resource id textview.

my main class

public class downloadlist extends listactivity {     private list<string> item = null;     private list<string> path = null;     private string root="/sdcard";     private textview mypath;     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.mydownload);         mypath = (textview)findviewbyid(r.id.path);         getdir(root);     }     private void getdir(string dirpath)     {         mypath.settext("location: " + dirpath);         item = new arraylist<string>();         path = new arraylist<string>();         file f = new file(dirpath);         file[] files = f.listfiles();         if(!dirpath.equals(root))         {             item.add(root);             path.add(root);             item.add("../");             path.add(f.getparent());         }         for(int i=0; < files.length; i++)         {             file file = files[i];             path.add(file.getpath());             if(file.isdirectory())                 item.add(file.getname() + "/");             else                 item.add(file.getname());         }         log.d("itemssssssss", item.tostring());         arrayadapter<string> filelist =                 new arrayadapter<string>(this, r.layout.rowmydownload, item);         setlistadapter(filelist);     } }  

my xml is

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#ffffffff"     android:orientation="vertical" >      <relativelayout         android:layout_width="fill_parent"         android:layout_height="50dp"         android:background="#a9d0f5"         android:orientation="horizontal" >          <imageview             android:id="@+id/image1"             android:layout_width="40dp"             android:layout_height="40dp"             android:layout_alignparentleft="true"             android:layout_centervertical="true"             android:layout_marginleft="8dp"             android:src="@drawable/untitled" />          <textview             android:id="@+id/txt1"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centervertical="true"             android:layout_marginleft="65dp"             android:layout_torightof="@+id/image1"             android:gravity="center"             android:text="my downloads"             android:textcolor="#000000"             android:textsize="26px"             android:textstyle="bold" />     </relativelayout>      <linearlayout         xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:orientation="vertical" >          <textview             android:id="@+id/path"             android:layout_width="fill_parent"             android:layout_height="wrap_content" />          <listview             android:id="@android:id/list"             android:layout_width="fill_parent"             android:layout_height="wrap_content" />          <textview             android:id="@android:id/empty"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:text="no data" />     </linearlayout>  </linearlayout> 

and row.xml is

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#ffffff"     android:orientation="vertical" >      <textview         xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/rowtext"         android:layout_width="fill_parent"         android:layout_height="25px"         android:textsize="23sp" />      <linearlayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_marginleft="50dp"         android:orientation="horizontal" >          <textview             android:id="@+id/course"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:text="sales training"             android:textcolor="#000000"             android:textstyle="bold" />     </linearlayout>      <linearlayout         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:layout_margintop="20dp"         android:orientation="horizontal" >          <button             android:layout_width="60dp"             android:layout_height="30dp"             android:layout_marginleft="90dp"             android:background="#81bef7"             android:text="view" />     </linearlayout>  </linearlayout> 

when using arrayadapter, first element of row.xml should textview, , not linearlayout.

if want use more 1 element in row, should not use arrayadapter, custom adapter. see example this android developer example


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -