2010-04-22 95 views
0

您好我在我的程序中访问run()方法时遇到问题。朗姆酒的方法并没有得到关注。是越来越显示日志信息是存在于循环外和我收到与预设background.Here的代码中的空白屏幕...在Android中访问运行()的问题

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(); 
       list(); 
       Log.d("handler","handler"); 
       removeDialog(0); 
       p.dismiss(); 


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

@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
     super.onResume(); 

} 

    public void webObjectList(Object[] songListObj) throws XMLRPCException{ 
    songNodeWeb = new HashMap<?,?>[songListObj.length]; 


    for(int i=0;i<songListObj.length;i++){ 
     songNodeWeb[i]=(HashMap<?,?>)songListObj[i]; 
     String nodeid=(String) songNodeWeb[i].get("nid"); 

     Log.e("Song",i+"completed"); 
     HashMap<String,String> nData=new HashMap<String,String>(); 
     nData.put("nid",nodeid);   
     Object nodeget=client.call("node.get",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("title_format"); 
     HashMap<?,?>[] songDetails=new HashMap<?,?>[songObject.length]; 
     songDetails[0]=(HashMap<?, ?>)songObject[0]; 
     String path=(String) songDetails[0].get("filepath"); 


     if(path.contains(" ")){ 
      path=path.replace(" ", "%20"); 
     } 

     String songPath="http://www.gorinka.com/"+path; 
     paths.add(songPath); 
     nData.put("path", songPath); 
     Log.e("my path",path); 
     SongsList songsList=new SongsList(title, album, artist,songPath,songPath); 
     SongsList.add(i,songsList); 
     songNodeDet.add(i,nData); 
    } 

    Log.e("paths values",paths.toString());  
    handler.sendEmptyMessage(0); 
} 

public void list() 
    {  Log.d("#####","#####"); 
    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/"; 
    URL u=new URL(ur); 
    client = new XMLRPCClient(u);  
    websongListObject =(Object[]) client.call("nodetype.get","titles"); 
    webObjectList(websongListObject); 
    Log.d("webObjectList","webObjectList"); 
    runOnUiThread(r); 
} 
private Handler handler = new Handler() { 
    public void handleMessage(Message msg){ 
     Log.d("handler","handler");   
     removeDialog(0); 
     p.dismiss(); 
    } 

}; }

我米试图通过简单的适配器来访问字符串...以下是适配器代码...

public class SongsAdapter extends SimpleAdapter{ 
static List<HashMap<String,String>> songsList; 
Context context; 
LayoutInflater inflater; 
public SongsAdapter(Context context,List<HashMap<String,String>> imgListWeb,int layout,String[] from,int[] to,LayoutInflater inflater) { 
    super(context,songsList,layout,from,to); 
    this.songsList=songsList; 
    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 v = ((LayoutInflater) inflater).inflate(R.layout.row,null); 
    ImageView images=(ImageView)v.findViewById(R.id.image); 
    TextView tvTitle=(TextView)v.findViewById(R.id.text1); 
    TextView tvAlbum=(TextView)v.findViewById(R.id.text2); 
    TextView tvArtist=(TextView)v.findViewById(R.id.text3); 
    HashMap<String,String> songsHash=songsList.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) v.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 v; 
    } 
    catch(Exception e){ 
     Log.e("error",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); 
    } 
} 

}

PLZ帮我determinre问题和解决我的问题...需要它很糟糕...

回答

0

首先,我会建议你使用AsyncTask

这里的错误是,你正在创建一个Runnable,但它没有传递给一个new Thread() 你缺少这样的事情:

Thread heavyLoader = new Thread(r); 
heavyLoader.start();