public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.artistname);
Bundle extras = getIntent().getExtras();
String val = extras.getString("artistname");
//Toast.makeText(getApplicationContext(), val, Toast.LENGTH_LONG).show();
String result = null;
InputStream is = null;
StringBuilder sb = null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
try{
//http post
HttpClient httpclient = new DefaultHttpClient();
//HttpPost httppost = new HttpPost("http://192.168.0.5/staging/android/get_search_result.php?keyword=Chinna_Mani&format=json");
HttpPost httppost =新HttpPost( 「http://192.168.0.5/staging/android/get_search_result.php?keyword=」 + VAL +」 &格式= JSON & FLG = 1" );機器人列表視圖適配器光標
//HttpPost httppost = new HttpPost("http://192.168.0.5/staging/android/ilaiyarajawebservice.php?format=xml");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e){
Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
}
//Convert response to string
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
}
//END Convert response to string
try{
JSONArray jArray = new JSONArray(result);
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++)
{
json_data = jArray.getJSONObject(i);
r.add(json_data.getString("artistfirstname"));
// r.add(json_data.getString("file_name")+json_data.getString("artist_name") +json_data.getString("album_name"));
}
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
if(null != cursor)
{
cursor.moveToFirst();
setListAdapter(new ArrayAdapter<String>(this,R.layout.custom_list_item, r));
}
else{
//我想這樣我在這裏警告下發展信息播放清單中找不到
System.out.println("playlist not found");
}
}
}
我需要幫助。如果有值r
內容則顯示,如果沒有內容,那麼我想設置警報「找不到列表」我如何實現這一目標?我嘗試使用其他但不成功。
提高您的問題... .... –
我張貼我的完整源代碼,它的工作不正常,請給解決方案 –