我在程序中访问run()方法时遇到问题。朗姆酒方法根本没有得到关注。循环外部显示的日志消息正在显示,我得到一个带预设背景的空白屏幕。这是代码......
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帮助我确定我的问题的问题和解决方案......非常需要......
答案 0 :(得分:0)
首先,我建议你使用AsyncTask。
这里的错误是您正在创建Runnable
但未将其传递给new Thread()
你错过了这样的东西:
Thread heavyLoader = new Thread(r);
heavyLoader.start();