problem displaying music list using custom adapters

by Rahul » Wed, 21 Apr 2010 02:30:33 GMT


Sponsored Links
 i, I am trying to display the list of songs using array adapters. But
the problem is i couldnt display the list and only empty screen with
preset background is showing up. Here's the code...All the thee are
seperate classes... Plz help me...

public class SongsAdapter extends ArrayAdapter<SongsList>{
private Context context;
TextView tvTitle;
TextView tvMovie;
TextView tvSinger;
String s;
Intent myintent = new Intent();

public SongsAdapter(Context context, int resource,
int textViewResourceId, ArrayList<String> al) {
super(context, resource, textViewResourceId);
this.context=context;


}

public View getView(int position, View convertView, ViewGroup parent)
{
final int i=position;

List<SongsList> listSongs = new ArrayList<SongsList>();
String title = listSongs.get(i).gettitleName().toString();
String album = listSongs.get(i).getmovieName().toString();
String artist = listSongs.get(i).getsingerName().toString();
String imgal = listSongs.get(i).gettitleName().toString();

myintent.getStringArrayListExtra(title);
myintent.getStringArrayListExtra(album);
myintent.getStringArrayListExtra(artist);
myintent.getStringArrayListExtra(imgal);

LayoutInflater inflater = ((Activity)
context).getLayoutInflater();
View v = inflater.inflate(R.layout.row, null);
tvTitle=(TextView)v.findViewById(R.id.text2);
tvMovie=(TextView)v.findViewById(R.id.text3);
tvSinger=(TextView)v.findViewById(R.id.text1);
tvTitle.setText(title);
tvMovie.setText(album);
tvSinger.setText(artist);

final ImageView im=(ImageView)v.findViewById(R.id.image);
s="http://www.gorinka.com/"+imgal;
String imgPath=s;
AsyncImageLoaderv asyncImageLoaderv=new
AsyncImageLoaderv();
Bitmap cachedImage =
asyncImageLoaderv.loadDrawable(imgPath, new
AsyncImageLoaderv.ImageCallback() {
public void imageLoaded(Bitmap imageDrawable, String
imageUrl) {

im.setImageBitmap(imageDrawable);
}
});
im.setImageBitmap(cachedImage);

return v;

}




public class imageloader implements Runnable{

private String ss;
private ImageView im;

public imageloader(String s, ImageView im) {
this.ss=s;
this.im=im;
Thread thread = new Thread(this);
thread.start();
}
public void run(){
try {

HttpGet httpRequest = null;
httpRequest = new HttpGet(ss);
HttpClient httpclient = new
DefaultHttpClient();
HttpResponse response = (HttpResponse)
httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();



problem displaying music list using custom adapters

by Rahul » Thu, 22 Apr 2010 12:34:44 GMT


  have tried to implement the above by using the following code...
But, this too is showing the same...


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{
Log.d("webObjectList","webObjectList");
getsongs();

} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLRPCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Log.e("mee","process over");
}

@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<?,?>[] songDetails=new
HashMap<?,?>[songObject.length];
songDetails[0]=(HashMap<?, ?>)songObject[0];
String path=(String) songDetails[0].g


Sponsored Links


problem displaying music list using custom adapters

by praj » Thu, 22 Apr 2010 13:13:12 GMT


 i Rahul,


Some things that I have noticed:

1) You have not initialized the SongsList item in the constructor. in
the constructor have a ArrayList and initialize it with the value that
you have passed (in your case "al").
2) in ur main activity u can use a setListAdapter it is very easy to
use and use the SongsAdapter object in it.
3) You can view Romain Guys video where he talks about how you can
handle list views. Try to use the convertView and only when the
convertView is null only then inflate and inflation is very expensive.
4) in ur getView you are using variable i - you can directly use
"position" for accessing.


What I would recommend is just try a simple listAdapter with text
views instead of displaying images as well and once that is done you
can add ur code for images.

Thanks,
Prajakta


On Apr 20, 6:06am, Rahul <rahulvarma.kalidindi0...@gmail.com> wrote:
>



Other Threads

1. Best way to logout each time the application/task goes to background

Hello,

I have an application which requires a login at the beginning (this is
the first activity). When the user logs in, I keep his credentials in
the application (I extended android.application to add a field called
'key'). I would like to clear this field from memory (from application
instance) an go back to the login activity.

I see the following possibilities:
- Add a broadcast receiver to catch all possible event (call, click on
menu, click on back, lock the phone ...) which clear the key field and
launch the login activity
- Use clearTaskOnLaunch for all activities except the login activity.
But then until my application takes the focus again the key stays in
the application object. (It seems it doesn't work with the go back
button, maybe I need to use no history also)
- Detect for each activity in all onPause or onStop events when
application will leave the foreground
 to clear the key field and launch the login activity

The best would be to have a kind of OnPause method at application
level but I think it doesn't exist

I would appreciate any help on this problem.

ps: I already posted it once but never saw it on the discussions list.

Cheers,
Kim

-- 

2. view and subview

is there a way i can create a view and add some textviews into it ?
programmatically ? any sample code ?

regards

-- 

3. Seems Android Market statistics go wrong again

4. FillBufferDone related

5. File operations extremely slow on emulator - totally stuck.

6. Tanya : Mohon minta review untuk HTC Wildfire ?

7. OOT : Wrestling Android Vs Apple