I have a list view.
each item has an imageview
currently I'm using SimpleAdapter but I can't set the image Bitmap.
I'm using two Array lists one for Bitmaps and one for texts. I'm currently using the texts array list with a simple adapter
Now I wan't to set the downloaded bitmaps for every item in the list. how can I do it ?
I must write an adapter or I can do this without writing adapters ?
you need to override getView , inflate a custom layout for the ListView's row, with an ImageView and TextView for instance, arranged the way you like, and set text and image on those.
You will indeed have to write your own custom adapter. Inside getView(), you will be able to instantiate your own layout xml containing an ImageView and a TextView which you can fill with your data.
This will get you started: http://www.vogella.com/tutorials/AndroidListView/article.html
Related
I am doing android application. In That I want to display a List of podcast urls like shown in the Image. In this I also share this url into FB, twitter and etc and also the user clicks the arrow symbol I want to forward to that podcast url.
I am having those values in separate arraylist (i.e. "4353,3424" as a arraylist and "567567, 234234" as a another arraylist likewise). So how can I display these values like shown in the attached image. Can anyone help me how to proceed to display like this?
I'd recommend you had a look at some of the tutorials on how to implement your own custom ListView.
An example can be found here: http://www.thepcwizard.in/2012/09/android-creating-custom-listview-for.html
Also I'd recommend you create a custom class for holding the different informations in every row of the ListView. When doing it like this you can have one single List<MyCustomObject> holding all informations and then when a row is clicked, you simple get the item from the List<MyCustomObject> and get the specific property of the custom object and act accordingly.
EDIT: Small example of how to add onClickListener to a sub-view of the row:
Inside the getView method of the custom Adapter you can use setOnClickListener to the views, you'd like to respond to clicks. For instance:
myImageView.setOnClickListener(this);
Then let your custom Adapter implement the interface OnClickListener and act accordingly to the clicks.
Another way would also be to add a Share Intent to the different images, like in this example:
http://sudarmuthu.com/blog/sharing-content-in-android-using-action_send-intent
You would need to create a custom ArrayAdapter to populate a ListView from this objects the way you want.
The advantage of this technic is that you gain a Views recycle mechanism that will recycle the Views inside you ListView in order to spend less memory.
In Short you would have to:
1. Create an object that represents your data for a single row.
2. Create an ArrayList of those objects.
3. Create a layout that contains a ListView or add a ListView to you main layout using code.
4. Create a layout of a single row.
5. Create a ViewHolder that will represent the visual aspect of you data row from the stand point of Views.
6. Create a custom ArrayAdapter that will populate the rows according to you needs.
7. Finally assign this ArrayAdapter to your ListView in onCreate.
You can get an Idea of how to implement this by reading this blog post I wrote:
Create a Custom ArrayAdapter
hi I want to use a listview (probably) is it possible to fill each entry with say two buttons two text areas, and have them laid out with realtive or linear layouts?
I have used a scroll view with layout inflator to achieve this at the moment, but I'm thinking listview would be better maybe?
yes you can. you need to use a custom list view for that. making an activity by adding a listview in it and then referencing another xml to that listview using an AAdapter so that every element of the listview has the layout of the second xml file. this tutorial should help you understand the idea.
Yes you can place any widgets for the particular List Item for your listview.
For defining that kind of ListView, you have to define a custom adapter, follow the below steps:
Define a one row file for the list item, say for example, RelativeLayout with 2-3 TextViews.
Define a class by extending BaseAdapter.
Inflate the XML and do display operations inside the getView() method of this class.
Set this adapter to the ListView.
We are developing an Android project. In that project we need to create a list view with multiple objects.
Inside each list view item we need to show Name, Mobile, Checkbox1 and Checkbox2
We tried with various options and we are clue less how to get this done.
You can create an .xml file, which contains a Layout (LinearLayout, RelativeLayout etc) and inside that layout put some Views like TextViews for the Name and Mobile and 2 CheckBox items for your checkboxes. I recommend this tutorial for more on ListView issues.
You need to define your own row layout and also your own ListAdapter implementation. The adapter needs to override getView to return your custom row view. There's a good example here that extends an ArrayAdapter. There's another example here that extends a CursorAdapter. Search the web for android custom listview row to get lots of other examples.
I found the following design in market of my tablet. I want to design a layout as like the below tables containing a image, text and a button for my android app. how to do this
You can achieve simple table look, by setting different colors to rows and cloumns and set appropriate margins in that here is example. Here he sets only border but you can fill any color or drawable inside column.
For this solution, i would suggest you to design custom adapter to be displayed either in GridView or in multi column ListView.
But i think GridView would be best to implement the above functionality.
Now, to define a custom adapter, you just have to create a simple class and extends BaseAdapter, and then you have to override the getView() method inside this class. Now within the getView() method, you can inflate() the custom row layout file (which you define for one item , this item xml layout file represents every items inside the GridView).
Here is the simple example for implementing a simple GridView.
For the detailed exmmple of such gridview, refer this example: Android - GridView example
I have a gridview that just needs to hold 4 buttons, how ever I keep getting an operation not supported in AdapterView error when executing. Can you even fill a gridview through xml?
You cannot add children to a GridView in XML. You need to create an appropriate Adapter and associate it with the GridView via setAdapter().
Most likely, if you only have four buttons, you do not want a GridView in the first place.