I am trying to display a list of containing images and text that i retrieved from a website. I have used the adapter. But the problem is that i couldnt access the array objects that i have declared. I am rather confused what the error is. I couldnt get the list but i am getting a blank screen...Here's the code...Plz help me....
public class SongsAdapter extends SimpleAdapter{
static List<HashMap<String,String>> songsListWeb;
Context context;
LayoutInflater inflater;
public SongsAdapter(Context context,List<HashMap<String,String>> imgListWeb,int layout,String[] from,int[] to,LayoutInflater inflater) {
super(context,songsListWeb,layout,from,to);
this.songsListWeb=songsListWeb;
this.context=context;
this.inflater=inflater;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int postition,View convertView,ViewGroup parent)throws java.lang.OutOfMemoryError{
try {
View rowView = ((LayoutInflater)
inflater).inflate(R.layout.row,null);
ImageView images=(ImageView)rowView.findViewById(R.id.image);
TextView tvTitle=(TextView)rowView.findViewById(R.id.text1);
TextView tvAlbum=(TextView)rowView.findViewById(R.id.text2);
TextView tvArtist=(TextView)rowView.findViewById(R.id.text3);
HashMap songsHash=songsListWeb.get(postition);
String path=songsHash.get("path");
String title=songsHash.get("title");
String album=songsHash.get("album");
String artist=songsHash.get("artist");
String imgPath=path;
final ImageView imageView = (ImageView) rowView.findViewById(R.id.image);
AsyncImageLoaderv asyncImageLoader=new AsyncImageLoaderv();
Bitmap cachedImage = asyncImageLoader.loadDrawable(imgPath, new
AsyncImageLoaderv.ImageCallback() {
public void imageLoaded(Bitmap imageDrawable, String imageUrl) {
imageView.setImageBitmap(imageDrawable);
}
});
imageView.setImageBitmap(cachedImage);
tvTitle.setText(title);
tvAlbum.setText(album);
tvArtist.setText(artist);
return rowView;
}
catch(Exception e){
Log.e("err",e.toString());
}
return null;
}
public static Bitmap loadImageFromUrl(String url) {
InputStream inputStream;Bitmap b;
try {
inputStream = (InputStream) new URL(url).getContent();
BitmapFactory.Options bpo= new BitmapFactory.Options();
bpo.inSampleSize=2;
b=BitmapFactory.decodeStream(inputStream, null,bpo );
return b;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
List Activity
public class MusicListActivity extends Activity {
List<HashMap<String, String>> songNodeDet = new ArrayList<HashMap<String,String>>();
HashMap<?,?>[] songNodeWeb;
XMLRPCClient client;
String logInSess;
ArrayList<String> paths=new ArrayList<String>();
public ListAdapter adapter ;
Object[] websongListObject;
List<SongsList> SongsList=new ArrayList<SongsList>();
Runnable r;
ProgressDialog p;
ListView lv;
@Override
public void onCreate(Bundle si){
super.onCreate(si);
setContentView(R.layout.openadiuofile);
lv=(ListView)findViewById(R.id.list1);
r=new Runnable(){
public void run(){
try{
getsongs();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLRPCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
public void webObjectList(Object[] songListObj,String logInSess) throws XMLRPCException{
songNodeWeb = new HashMap<?,?>[songListObj.length];
for(int i=0;i<songListObj.length;i++){ //imgListObj.length
songNodeWeb[i]=(HashMap<?,?>)songListObj[i];
String nodeid=(String) songNodeWeb[i].get("nid");
Log.e("img",i+"completed");
HashMap<String,String> nData=new HashMap<String,String>();
nData.put("nid",nodeid);
Object nodeget=client.call("node.get",logInSess,nodeid);
HashMap<?,?> songNode=(HashMap<?,?>)nodeget;
String title=(String) songNode.get("title");
String album=(String) songNode.get("album");
String artist=(String) songNode.get("artist");
nData.put("title", title);
nData.put("album", album);
nData.put("artist", artist);
Object[] songObject=(Object[])songNode.get("field_image");
HashMap<?,?>[] imgDetails=new HashMap<?,?>[songObject.length];
imgDetails[0]=(HashMap<?, ?>)songObject[0];
String path=(String) imgDetails[0].get("filepath");
if(path.contains(" ")){
path=path.replace(" ", "%20");
}
String imgPath="http://www.gorinka.com/"+path;
paths.add(imgPath);
nData.put("path", imgPath);
Log.e("my path",path);
String mime=(String)imgDetails[0].get("filemime");
nData.put("mime", mime);
SongsList songsList=new SongsList(title, album, artist, imgPath,imgPath);
SongsList.add(i,songsList);
songNodeDet.add(i,nData);
}
Log.e("paths values",paths.toString());
handler.sendEmptyMessage(0);
}
private Runnable returnRes = new Runnable() {
@Override
public void run() {
Log.d("handler","handler");
removeDialog(0);
p.dismiss();
bbb();
}
};
public void bbb()
{ Log.d("bbb","bbb");
LayoutInflater inflater=getLayoutInflater();
String[] from={};
int[] n={};
adapter=new SongsAdapter(getApplicationContext(),songNodeDet,R.layout.row,from,n,inflater);
lv.setAdapter(adapter);
}
public void getsongs() throws MalformedURLException, XMLRPCException
{
String ur="http://www.gorinka.com/?q=services/xmlrpc";
URL u=new URL(ur);
client = new XMLRPCClient(u);
HashMap<?, ?> siteConn =(HashMap<?, ?>) client.call("system.connect");
String initSess=(String)siteConn.get("sessid");
HashMap<?, ?> logInConn =(HashMap<?, ?>) client.call("user.login",initSess,"username","password");
logInSess=(String)logInConn.get("sessid");
websongListObject =(Object[]) client.call("nodetype.get",logInSess,"images");
webObjectList(websongListObject,logInSess);
Log.d("webObjectList","webObjectList");
runOnUiThread(returnRes);
}
private Handler handler = new Handler() {
public void handleMessage(Message msg){
Log.d("handler","handler");
removeDialog(0);
p.dismiss();
}
};
}