Search in sources :

Example 1 with ReplyList

use of com.v2ex.api.ReplyList in project V2HOT by djyde.

the class ContentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(false);
    }
    setContentView(R.layout.activity_content);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
    ImageLoader.getInstance().init(config);
    Intent intent = getIntent();
    String id = intent.getStringExtra("id");
    String content = intent.getStringExtra("content");
    String username = intent.getStringExtra("username");
    title = intent.getStringExtra("title");
    url = intent.getStringExtra("url");
    final RepliesAdapter repliesAdapter = new RepliesAdapter(this, username);
    ListView repliesView = (ListView) findViewById(R.id.replies);
    View headerView = getLayoutInflater().inflate(R.layout.topic_header, repliesView, false);
    ((TextView) headerView.findViewById(R.id.header_title)).setText(title);
    ((TextView) headerView.findViewById(R.id.header_content)).setText(content);
    ((TextView) headerView.findViewById(R.id.header_username)).setText(username);
    repliesView.addHeaderView(headerView);
    repliesView.setAdapter(repliesAdapter);
    RequestQueue queue = Volley.newRequestQueue(ContentActivity.this);
    //获取回复
    queue.add(new GsonRequest<ReplyList>(Request.Method.GET, "https://www.v2ex.com/api/replies/show.json?topic_id=" + id, ReplyList.class, new Response.Listener<ReplyList>() {

        @Override
        public void onResponse(ReplyList response) {
            repliesAdapter.addAll(response);
            repliesAdapter.notifyDataSetChanged();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(ContentActivity.this, "请检查网络", Toast.LENGTH_LONG).show();
        }
    }));
}
Also used : VolleyError(com.android.volley.VolleyError) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ListView(android.widget.ListView) RequestQueue(com.android.volley.RequestQueue) TextView(android.widget.TextView) ReplyList(com.v2ex.api.ReplyList) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) ActionBar(android.support.v7.app.ActionBar)

Aggregations

Intent (android.content.Intent)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 RequestQueue (com.android.volley.RequestQueue)1 VolleyError (com.android.volley.VolleyError)1 ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)1 ReplyList (com.v2ex.api.ReplyList)1