简体   繁体   English

单击列表视图中的项目时,如何解析不同的json url?

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

So my code consist of parsing json urls and getting the values from the rotten tomato api. 因此,我的代码包括解析json网址并从烂番茄api获取值。 What I cant figure out is how to have a list view and when a users clicks on box office they should parse through the box office api. 我无法弄清楚的是如何拥有一个列表视图,当用户单击票房时,他们应该通过票房api进行解析。 If a users clicks on upcoming movies than that url should be parsed. 如果用户单击即将上映的电影,则应解析该URL。 Parse works just need to fix my listview 解析作品只需要修复我的列表视图

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;
}

}

try this: 尝试这个:

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