Using simpleAdapter with image for listview - android

I have a little problem with putting an image to a list view using simple adapter. I'm getting the image from my online server(AMAZON). After downloading the image based on the user id, i try to set them in my listview but nothing was display and no error is occured.
Below is my code:
// looping through All applicants
for (int i = 0; i < applicant.length(); i++) {
JSONObject c = applicant.getJSONObject(i);
// Storing each JSON item in variable
String uid = c.getString(TAG_UID);
String name = c.getString(TAG_NAME);
String overall = c.getString(TAG_OVERALL);
String apply_datetime = c.getString(TAG_APPLY_DATETIME);
String photo = c.getString(TAG_PHOTO);
// creating new HashMap
//HashMap<String, String> map = new HashMap<String, String>();
//IMAGE
HashMap<String, Object> map = new HashMap<String, Object>();
// adding each child node to HashMap key (value)
map.put(TAG_UID, uid);
map.put(TAG_NAME, name);
map.put(TAG_OVERALL, overall);
map.put(TAG_APPLY_DATETIME, apply_datetime);
// adding HashList to ArrayList
// applicantsList.add(map);
// LISTING IMAGE TO LISTVIEW
try {
imageURL = c.getString(TAG_PHOTO);
InputStream is = (InputStream) new URL(
"my url link/images/"
+ imageURL).getContent();
d = Drawable.createFromStream(is, "src name");
} catch (Exception e) {
e.printStackTrace();
}
map.put(TAG_PHOTO, d);
// adding HashList to ArrayList
applicantsList.add(map);
}
As you can see, after i download the image. i set to listview using simpleAdapter below:
SimpleAdapter adapter = new SimpleAdapter(
SignUpApplicantActivity.this, applicantsList,
R.layout.list_applicant, new String[] {
TAG_UID, TAG_NAME, TAG_OVERALL,
TAG_APPLY_DATETIME, TAG_PHOTO }, new int[] {
R.id.applicantUid, R.id.applicantName,
R.id.applicantOverall,
R.id.apply_datetime, R.id.list_image });
// updating listView
setListAdapter(adapter);

Did you called notifyDatasetChange() ? your adapter may not be invalidated if you don't call it.

From the SimpleAdapter documentation the image data is expected to be a resource ID or a string (an image URI) - see setViewImage(ImageView,String)
I see 2 solutions:
Provide a URI in the data map, not a drawable.
Implement your own view binder to bind the drawable to the ImageView:
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if(view.getId() == R.id.list_image) {
ImageView imageView = (ImageView) view;
Drawable drawable = (Drawable) data;
imageView.setImageDrawable(drawable);
return true;
}
return false;
}
});

Try
try{
for (int i = 0; i < applicant.length(); i++) {
JSONObject c = applicant.getJSONObject(i);
// Storing each JSON item in variable
String uid = c.getString(TAG_UID);
String name = c.getString(TAG_NAME);
String overall = c.getString(TAG_OVERALL);
String apply_datetime = c.getString(TAG_APPLY_DATETIME);
String photo = c.getString(TAG_PHOTO);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key (value)
map.put(TAG_UID, uid);
map.put(TAG_NAME, name);
map.put(TAG_OVERALL, overall);
map.put(TAG_APPLY_DATETIME, apply_datetime);
map.put(TAG_PHOTO, photo);
// adding HashList to ArrayList
applicantsList.add(map);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
SimpleAdapter adapter = new SimpleAdapter(
SignUpApplicantActivity.this, applicantsList,
R.layout.list_applicant, new String[] {
TAG_UID, TAG_NAME, TAG_OVERALL,
TAG_APPLY_DATETIME, TAG_PHOTO }, new int[] {
R.id.applicantUid, R.id.applicantName,
R.id.applicantOverall,
R.id.apply_datetime, R.id.list_image });
// updating listView
setListAdapter(adapter);
Maybe my code can help you!?!
I have made
convertDrawable(int Integer)
and String.valueOf(convertDrawable(iconId))
HashF.put(TAG_ID, String.valueOf(convertDrawable(iconId)));
private void getList(JSONObject json) {
try {
details = json.getJSONArray(TAG_LIST);
for (int i = 0; i < details.length(); i++) {
JSONObject main = details.getJSONObject(i);
Integer date = main.getInt(TAG_DATE);
JSONArray nArray = main.getJSONArray(TAG_NOW);
JSONObject detail = nArray.getJSONObject(0);
Integer iconId = detail.getInt(TAG_ID);
HashMap<String, String> HashF = new HashMap<String, String>();
HashF.put(TAG_DATE, convertDate(date));
HashF.put(TAG_ID, String.valueOf(convertDrawable(iconId)));
fList.add(HashF);
}
} catch (Exception e) {
}
ListAdapter adapter =
new SimpleAdapter(getActivity(),
fList, R.layout.list_item,
new String[]{
TAG_DATE,
TAG_ID
},
new int[]{
R.id.datum,
R.id.icon_fore
});
setListAdapter(adapter);
}
public static String convertDate(Integer Time) {
SimpleDateFormat sdf =
new SimpleDateFormat(
"dd, MMMM", Locale.getDefault());
Calendar kal =
Calendar.getInstance();
kal.setTimeInMillis(Time * 1000L);
sdf.setTimeZone(kal.getTimeZone());
return sdf.format(kal.getTime());
}
public static int convertDrawable(int aId){
int icon = 0;
if(aId == 8300){
icon = R.drawable.draw1;
}
if (aId >= 7010 && actualId < 7919){
icon = R.drawable.draw2;
}
if (aId >= 2010 && actualId <3010) {
icon = R.drawable.draw3;
}
if (aId >= 3010 && actualId < 4010) {
icon = R.drawable.draw4;
}
if (aId >= 6010 && actualId < 7010) {
icon = R.drawable.draw5;
}
if (aId >= 5010 && actualId < 6010) {
icon = R.drawable.draw6;
}
if (aId == 3801){
icon = R.drawable.draw7;
}
if (aId == 8032){
icon = R.drawable.draw8;
}
if (aId == 8083){
icon = R.drawable.draw9;
}
if (aId == 8704) {
icon = R.drawable.draw10;
}
return icon;
}
Anyway make a look at Bitmap is not a Drawable

Related

Error when selecting an item in my spinner

I am getting an error java.lang.String cannot be cast to java.util.HashMap when i select a data on my spinner. I retrieve my data in my spinner from my database. Im am trying to have just only 1 class, when i select a item on my spinner it checks the id in my database to show filter and show only the selected id
Here is my spinner select
ArrayList<HashMap<String,String>> list1 = new ArrayList<>();
try
{
JSONArray JA = new JSONArray(result);
JSONObject json;
s_name = new String[JA.length()];
s_gender = new String[JA.length()];
for(int i = 0; i<JA.length(); i++)
{
json = JA.getJSONObject(i);
s_gender[i] = json.getString("s_gender");
s_name[i] = json.getString("s_name");
}
list1.add("All");
for(int i = 0; i<s_name.length; i++)
{
list1.add(s_name[i] + " "+s_gender[i]);
}
} catch (JSONException e) {
e.printStackTrace();
}
spinner_fn();
ArrayList<HashMap<String,String>> spinner = new ArrayList<Object>(Games.this, layout.simple_spinner_dropdown_item, s_name);
spinner1.setAdapter((SpinnerAdapter) spinner);
spinner1.setSelection(0);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Intent intent = null;
switch (position) {
case 1:
intent = new Intent(getApplication(), Basketball.class);
HashMap<Object, Object> map = (HashMap)parent.getItemAtPosition(position);
String news_id = map.get(Config.TAG_news_id).toString();
String title = map.get(Config.TAG_title).toString();
String content = map.get(Config.TAG_content).toString();
String n_date = map.get(Config.TAG_n_date).toString();
intent.putExtra(Config.News_id,news_id);
intent.putExtra(Config.Title,title);
intent.putExtra(Config.Content,content);
intent.putExtra(Config.N_date,n_date);
startActivity(intent);
break;
I am getting the error here saying in arraylist cannot be applied to java.lang.string
(Games.this, layout.simple_spinner_dropdown_item, s_name);
list1.add("All");
for(int i = 0; i<s_name.length; i++)
{
list1.add(s_name[i] + " "+s_gender[i]);
}
list1.add(s_name[i] + " "+s_gender[i]);
here is an error, as list1 is ArrayList of HASHMAP (you have a lot of hashmaps in one arraylist), and you've tried to add usual String to this list. May be you wanted the next:
for(int i = 0; i<s_name.length; i++)
{
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put(s_name[i], s_gender[i]);
list1.add(hashMap);
}
//Remove this line
list1.add("All");
use this.
HashMap<String,String> stringHashMap=new HashMap<>();
for(int i = 0; i<s_name.length; i++)
{
stringHashMap.put(s_name[i],s_gender[i]);
list1.add(stringHashMap);
}
ArrayList<String> spinnerArray=new ArrayList<>();
Map<String, String> map = stringHashMap;
for (Map.Entry<String, String> entry : map.entrySet()) {
spinnerArray.add(entry.getKey());
}
ArrayAdapter<String> spinner = new ArrayAdapter<String>(Games.this, layout.simple_spinner_dropdown_item, spinnerArray);
spinner1.setAdapter(spinner);
spinner1.setSelection(0);

Set listview with encoded string image android

There's someway for me to adapt a encoded string image in a Listview?
I got from my server, in base64 format, a image in a string, and I want to set it in a Listview with some text.
Here is part of my code:
for (int i = 0; i < makers.length(); i++) {
JSONObject c = makers.getJSONObject(i);
// Storing each json item in variable
String name = c.getString(TAG_NAME);
String age = c.getString(TAG_AGE);
String username = c.getString(TAG_USERNAME);
String rating = c.getString(TAG_RATING);
String disc = c.getString(TAG_DISC);
Long date = c.getLong(TAG_DATE);
String num = c.getString(TAG_NUM);
// creating new HashMap
//HashMap<String, String> map = new HashMap<String, String>();
Map map = new HashMap<String, Bitmap>();
String image=c.getString(TAG_IMAGE1);
byte[] decodedString = Base64.decode(image, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
map.put(TAG_NAME, name);
map.put(TAG_USERNAME, username);
map.put(TAG_AGE, age);
map.put(TAG_RATING, rating);
map.put(TAG_DISC, disc);
map.put(TAG_NUM, num);
map.put(TAG_IMAGE1, bitmap);
// map.put(TAG_CIDADE, cidade);
long curdate = System.currentTimeMillis();
long onem = curdate - date;
long intm = 3*30*24*60*60*1000 ;
if(onem >= intm){
} else {
// adding HashList to ArrayList
userdataList.add((HashMap<String, String>) map);
}
}
}
And here is my Adapter:
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting the related idioms
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
ListResult1.this, userdataList,
R.layout.list_view, new String[] { TAG_NAME, TAG_USERNAME, TAG_AGE, TAG_RATING, TAG_DISC, TAG_NUM, TAG_IMAGE1},
new int[] {R.id.name, R.id.username, R.id.age, R.id.rating, R.id.disc, R.id.num, R.id.ivimage1s});
// updating listview
setListAdapter(adapter);
}
});
}
And i want also to transfer that image through a intent, it's possible?
The actual problem is that I can't set a adapter for my image, all the text part work just fine, but the image did not loaded.
Sorry for any English issue, it's not my mother language.

how to show data that get from selected listview in another activity

i have an app where in a form show the list view. the user can click one of the list view and when clicking the app will move to another activity and it's activity will show some data based on "code" that sent from the list view form. my app is success to move in another activity but doesn't show the data. please help me.
Thank you.
This is my code in list view form :
final ListView lv = (ListView)findViewById(R.id.lv);
String url = "http://192.168.43.244/wewash/listview.php";
try {
JSONArray data = new JSONArray(getJSONUrl(url));
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("nama", c.getString("nama"));
map.put("tanggal_keluar", c.getString("tanggal_keluar"));
MyArrList.add(map);
}
SimpleAdapter sAdap;
sAdap = new SimpleAdapter(halaman_utama.this, MyArrList, R.layout.listview,
new String[] {"nama", "tanggal_keluar","id", ""}, new int[] {R.id.tsnama, R.id.tstglk, R.id.kode, R.id.tsspasi});
lv.setAdapter(sAdap);
lv.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String kode = ((TextView) findViewById(R.id.kode)).getText().toString();
Intent in = new Intent(halaman_utama.this, p_daftar_pakaian.class);
//menampilkan value dari item yg diklik
in.putExtra("id", kode);
startActivity(in);
}
});
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
and it's my code in new activity :
Intent intent = getIntent();
String kode = intent.getStringExtra("id");
String url = "http://192.168.43.244/wewash/listview_detail.php?id="+kode;
try {
JSONArray data = new JSONArray(getJSONUrl(url));
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
String idpk = c.getString("id");
String namapk = c.getString("nama");
String paketpk = c.getString("paket");
String cbiasapk = c.getString("cbiasa");
String ckhususpk = c.getString("ckhusus");
String tglantarpk = c.getString("tanggal_keluar");
String totalpk = c.getString("total");
// String nomorpk = c.getString("no_hp");
atasnama.setText(namapk);
ereview.setText("Id Pelanggan : " +idpk+
"\nNama Pelanggan : "+namapk+
"\nPaket : "+paketpk+
"\nCucian Biasa : "+cbiasapk+" kg"+
"\nCucian Khusus : "+ckhususpk+" item"+
"\nTotal : "+totalpk+" rupiah"+
"\nTanggal Antar : "+tglantarpk);
// enomer.setText(nomorpk);
}
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
and it's the php file
<?php
mysql_connect("localhost","root","");
mysql_select_db("wewash");
$kode=$_GET["id"];
$sql=mysql_query("select * from pakaian where id='$kode'");
$arrayId=array();
if($sql === FALSE) {
die(mysql_error());
}
while($row=mysql_fetch_array($sql)){
$arrayId["id"]=$row["id"];
$arrayId["nama"]=$row["nama"];
$arrayId["tanggal_keluar"]=$row["tanggal_keluar"];
$arrayId["paket"]=$row["paket"];
$arrayId["cbiasa"]=$row["cbiasa"];
$arrayId["ckhusus"]=$row["ckhusus"];
$arrayId["total"]=$row["total"];
}
echo json_encode($arrayId);
?>

Converting a bitmap image from JSON array to a hashmap

I was trying to put a JSON array of object into a hashmap.The object contains images which is in base64 format.I converted the image to bit map and need to put the image in a List view using a hashmap.But i am getting a null pointer exception
#Main Activity#
protected void onPostExecute(JSONObject json) {
try {
// Getting JSON Array from URL
details = json.getJSONArray(TAG_Root);
for(int i = 0; i < details.length(); i++){
JSONObject c = details.getJSONObject(i);
// Storing JSON item in a Variable
String branch = c.getString(TAG_Branch);
String address = c.getString(TAG_Add);
String uname = c.getString(TAG_User);
String photo = c.getString(TAG_Photo);
//decoding the base64 image to an png format
byte[] imageAsBytes = Base64.decode(photo.getBytes(), Base64.DEFAULT);
ImageView image = (ImageView)findViewById(R.id.imageView1);
image.setImageBitmap(
BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_Branch, branch);
map.put(TAG_Add, address);
map.put(TAG_User, uname);
oslist.add(map);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(TAG_Photo,image);
oslist.add(map);
//String.valueOf(TAG_Photo
//,R.id.imageView1
list=(ListView)findViewById(R.id.listView1);
ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
R.layout.list_activity,
new String[] { TAG_Branch,TAG_Add, TAG_User }, new int[] {
R.id.textView1,R.id.textView2, R.id.textView3});
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int pos=position;
Toast.makeText(MainActivity.this, "You Clicked at "+oslist.get(+pos).get("name"), Toast.LENGTH_SHORT).show();
}
});
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
You're getting null because of the map
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(TAG_Photo,image);
the adapter won't find the needed tags in it so it will give null exception.
If photo's value is base64 string content, I think you don't need photo.getBytes()
String photo = jsonObject.getString(TAG_Photo);
byte[] bytes = Base64.decode(photo, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

Android ExpandableList - Image Loader - Simple Adapter

i need very much our help.
I need create a expandableListView and put inside more images loaded to url.
Now i have this:
i take the text to file xml but i dunno how show in image my image dinamic.
This is code:
Main.java
public class Main extends ExpandableListActivity {
static final String KEY_DISCOUNTED_PRICE = "discounted_price";
static final String KEY_PRICE = "price";
static final String KEY_DISCOUNT = "discount";
static final String KEY_THUMB_URL_SELLER = "seller_image_url";
static final String KEY_THUMB_URL = "image_url";
static final String KEY_DESCRIPTION = "description";
static final String KEY_TITLE_OFFERTA = "title_offerta";
String contenuto_nodo;
ArrayList <String> array_contenuto_nodo =new ArrayList<String>();
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
static final String shades[][] = {
// Shades of grey
{
"lightgrey","#D3D3D3",
"dimgray","#696969",
"sgi gray 92","#EAEAEA"
},
// Shades of blue
{
"dodgerblue 2","#1C86EE",
"steelblue 2","#5CACEE",
"powderblue","#B0E0E6"
},
// Shades of yellow
{
"yellow 1","#FFFF00",
"gold 1","#FFD700",
"darkgoldenrod 1"," #FFB90F"
},
// Shades of red
{
"indianred 1","#FF6A6A",
"firebrick 1","#FF3030",
"maroon","#800000"
}
};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
TaskHomePageLista task = new TaskHomePageLista();
task.execute();
try {Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// ImageLoader class instance
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(), // groupData describes the first-level entries
R.layout.list_row, // Layout for the first-level entries
new String[] { KEY_PRICE, KEY_DISCOUNT, KEY_DESCRIPTION, KEY_DISCOUNTED_PRICE, KEY_TITLE_OFFERTA}, // Key in the groupData maps to display
new int[] { R.id.price, R.id.discount, R.id.description, R.id.discounted_price, R.id.title_offerta}, // Data under "colorName" key goes into this TextView
createChildList(), // childData describes second-level entries
R.layout.child_row, // Layout for second-level entries
new String[] { "shadeName", "rgb" }, // Keys in childData maps to display
new int[] { R.id.childname, R.id.rgb }
);
setListAdapter( expListAdapter );
// Imageview to show
}
/**
* Creates the group list out of the colors[] array according to
* the structure required by SimpleExpandableListAdapter. The resulting
* List contains Maps. Each Map contains one entry with key "colorName" and
* value of an entry in the colors[] array.
*/
private List createGroupList() {
return (List)songsList;
}
/**
* Creates the child list out of the shades[] array according to the
* structure required by SimpleExpandableListAdapter. The resulting List
* contains one list for each group. Each such second-level group contains
* Maps. Each such Map contains two keys: "shadeName" is the name of the
* shade and "rgb" is the RGB value for the shade.
*/
private List createChildList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < shades.length ; ++i ) {
// Second-level lists
ArrayList secList = new ArrayList();
for( int n = 0 ; n < shades[i].length ; n += 2 ) {
HashMap child = new HashMap();
child.put( "shadeName", shades[i][n] );
child.put( "rgb", shades[i][n+1] );
secList.add( child );
}
result.add( secList );
}
return result;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
class TaskHomePageLista extends AsyncTask<String, Void, Void> {
protected void onPreExecute(Void... params) {
}
protected Void doInBackground(String... args) {
try {
// passo i parametri di mail e password alle variabili
//setto la pagina
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost("http://www.miosito.HomePageXml.aspx");
// aggiungo alla lista le variabili
// chiamo la pagina che mi da una risposta.
HttpResponse response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(in);
String[] nomi = new String[6];
nomi[0] = "price";
nomi[1] = "image_url";
nomi[2] = "seller_image_url";
nomi[3] = "discount";
nomi[4] = "discounted_price";
nomi[5] = "description";
if (doc != null) {
// dichiaro n3 per la lunghezza dell'item principale di quello che devo selezionare.
NodeList n3 = doc.getElementsByTagName("promo");
NodeList n2 = doc.getElementsByTagName("home");
for (int i = 0; i < n3.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
for( int num=0; num < nomi.length; num++){
n2 = doc.getElementsByTagName(nomi[num]);
if (n2.getLength() > 0) {
Node node = n2.item(i);
contenuto_nodo = node.getTextContent();
array_contenuto_nodo.add(contenuto_nodo+"///");
if(nomi[num].equals("price")){
map.put(KEY_PRICE, "Valore" + Html.fromHtml("<BR>" + node.getTextContent() + " €"));
}
if(nomi[num].equals("image_url")){
map.put(KEY_THUMB_URL, node.getTextContent());
}
// if(nomi[num].equals("seller_image_url")){
// map.put(KEY_THUMB_URL_SELLER, node.getTextContent());
// }
if(nomi[num].equals("discount")){
map.put(KEY_DISCOUNT, "Sconto" + Html.fromHtml("<BR>" + node.getTextContent() + " %"));
}
if(nomi[num].equals("discounted_price")){
map.put(KEY_DISCOUNTED_PRICE, node.getTextContent()+ " €");
}
if(nomi[num].equals("description")){
map.put(KEY_DESCRIPTION, node.getTextContent());
}
System.out.println("sto elaborando");
}
n2 = doc.getElementsByTagName("home");
}
n2 = doc.getElementsByTagName("promo");
if (n2.getLength() > 0) {
Node node = n2.item(i);
node = node.getFirstChild();
map.put(KEY_TITLE_OFFERTA, node.getTextContent());
}
songsList.add(map);
}
System.out.println("array_titolo_categoria_home is: " + array_contenuto_nodo );
// controllo_login_tempo = "finito";
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void... params) {
}
}
}
In KEY_THUMB_URL after AsynkTask i have the url of image. I need show at harth with image loader. But i dunno how implement image loader in the SimpleExpandableListAdapter. Please help me is very important!
I think i can use this:
int loader = R.drawable.loader;
// Imageview to show
ImageView image = (ImageView) findViewById(R.id.image);
// Image url
String image_url = "http://api.androidhive.info/images/sample.jpg";
// ImageLoader class instance
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
// whenever you want to load an image from url
// call DisplayImage function
// url - image url to load
// loader - loader image, will be displayed before getting image
// image - ImageView
imgLoader.DisplayImage(image_url, loader, image);
but i dunno where i must put this code... Please help!
Look this image for screen
http://www.magicfly.it/app/screen.jpg
Finally I found a solution.
"This class can be used by external clients of SimpleAdapter to bind values to views. You should use this class to bind values to views that are not directly supported by SimpleAdapter or to change the way binding occurs for views supported by SimpleAdapter."
So ImageView. The expected bind value is a resource id or a string and setViewImage(ImageView, int) or setViewImage(ImageView, String) is invoked.
public class MyViewBinder implements ViewBinder {
#Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if ((view instanceof ImageView) & (data instanceof Bitmap)) {
ImageView iv = (ImageView) view;
Bitmap bm = (Bitmap) data;
iv.setImageBitmap(bm);
return true;
}
return false;
}
}
and
HashMap<String, Object> man = new HashMap<String,Object>();
Bitmap bitmap = BitmapFactory.decodeStream(aURL.openStream());
modles.put(samURL,bitmap);
then
adapter.setViewBinder(new MyViewBinder()); //its below declaration of adapter
source : click here

Categories

Resources