0

I want to populate a list view with an array list. The array list is fetched from a soap web service response.
I have used it as following:

mylistview = (ListView)findViewById(R.id.list);

listAdapter = new ArrayAdapter<Plant>(MainActivity.this,
             android.R.layout.simple_list_item_1, array_books);
mylistview.setAdapter(listAdapter);

It display following in list view:

Book{id=1; name= C++; imagepath=https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GW3ixVIGHLrrXb2yN_6i;}

Book{id=2; name= Java; imagepath=https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GW3ixVyN_6i;}

Book{id=3; name=Android; imagepath=https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GW3HLrrXb2yN_6i;}

I want to display the image by retrieving it from its path in Image View and display only name of book like: image ................ Java

When I change the layout in

listAdapter = new ArrayAdapter<Book>(MainActivity.this,
                 android.R.layout.row, array_books);

it gives error that row cannot resolved as a resource. But row.xml is present in the layout folder. How can I correct this error and display the items I want in the list view?

1
  • 1
    Try to change android.R.layout.row to R.layout.row Commented Jul 16, 2014 at 7:02

3 Answers 3

2

Try this

listAdapter = new ArrayAdapter<Plant>(MainActivity.this,
            R.layout.row, array_books);// Change  android.R.layout.row to R.layout.row

Your row is present in your layout so need to find using R.layout.row

Sign up to request clarification or add additional context in comments.

9 Comments

It worked. And how to get only particular part of array list like only book name.??
@user3823856 you need override toString() method on Plant class then return anything you want like " return title; "
@user3823856 I didn't get you. What are you talking about?
@user3823856 use a custom adapter in that case.
Ok. Thanks to you all.
|
0

Use R.layout.row instead of android.R.layout.row

Comments

0

As @Giru pointed out, if your xml file row.xml is in your layout folder, you can't reference it by android.R

The android.R object has references to the resources bundled with Android.

Your resources are simply under your.package.R so in your file just remove the "android." and have

listAdapter = new ArrayAdapter<Plant>(MainActivity.this,
            R.layout.row, array_books);

and you should be good to go.

1 Comment

You all pointed out my mistake correctly. And how to get only particular part of array list like only book name.??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.