簡體   English   中英

單擊列表視圖中的項目時,如何解析不同的json url?

[英]How can I parse different json urls when clicking on an item in a listview?

因此,我的代碼包括解析json網址並從爛番茄api獲取值。 我無法弄清楚的是如何擁有一個列表視圖,當用戶單擊票房時,他們應該通過票房api進行解析。 如果用戶單擊即將上映的電影,則應解析該URL。 解析作品只需要修復我的列表視圖

public class MainActivity extends Activity {
String boxOfficeUrl ="http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?page_limit=50&page=1&country=us&apikey=arjrkxx65yxywyefb8g2xxhs";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new AsyncBox().execute(boxOfficeUrl);

}

protected void onPostExecute(List<Movie> result){

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

嘗試這個:

ArrayList <String> listItems = new ArrayList<String>();
ArrayAdapter <String> adapter;
ListView listView;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new AsyncBox().execute(boxOfficeUrl);
    listView = (ListView) findViewById(R.id.listView1);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
}

protected void onPostExecute(List<Movie> result){
    adapter.addAll(result);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM