0
我正在創建一個電影目錄應用程序。我有一個問題,我想獲得detailmovie
(從電影ID)。我從listview
發送ID電影,我已經創建了DetailActivity
,我測試了電影標題,但它不起作用。我能做什麼?Android - JSON到使用asynctask的textview
這裏是我的代碼
public class DetailActivity extends AppCompatActivity {
TextView txt_title,txt_detail,txt_rate;
ImageView img_posterd;
public static String API_KEY = "f00e74c69ff0512cf9e5bf128569f****";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Intent i = getIntent();
String idmov = i.getStringExtra("idmovie");
String url = "https://api.themoviedb.org/3/movie/"+idmov+"?api_key="+API_KEY+"&language=en-US";
txt_title = (TextView) findViewById(R.id.tv_title_detail);
new GetMovieTask(txt_title).execute(url);
}
private class GetMovieTask extends AsyncTask<String, Void, String>{
TextView txt_title;
public GetMovieTask(TextView txt_title) {
this.txt_title = txt_title;
}
@Override
protected String doInBackground(String... strings) {
String title = "UNDEFINED";
try {
URL url = new URL(strings[0]);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
JSONObject object = new JSONObject();
title = object.getString("original_title");
urlConnection.disconnect();
Log.d("titlenya", title);
}catch (IOException | JSONException e){
e.printStackTrace();
}
return title;
}
@Override
protected void onPostExecute(String original_title) {
txt_title.setText("Ti : " +original_title);
}
}
}
我使用themoviedb
API。用於listview的loopj庫。
什麼是不工作?此外,你永遠不想顯示你的API密鑰。 – Cheticamp
我的Log.d沒有顯示,, textview沒有改變 –
你在logcat中出現錯誤? – Cheticamp