示例#1
0
  private void setListeners() {
    findViewById(R.id.ps_back).setOnClickListener(this);
    findViewById(R.id.ps_search_delete).setOnClickListener(this);
    searchBtn.setOnClickListener(this);
    searchResultListView.setOnRefreshListener(this);
    searchResultListView.setPullToRefresh(false);
    searchResultListView.setOnItemClickListener(onItemClickListener);
    input.setOnEditorActionListener(
        new OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE
                || actionId == EditorInfo.IME_ACTION_SEARCH) {
              searchBtn.performClick();
            }
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
              searchBtn.performClick();
              return true;
            }
            return false;
          }
        });
  }
  // String []
  // newsdatas={"最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻","最新新闻"};
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.titletext = "新闻列表";

    super.onCreate(savedInstanceState);
    super.leftbutton.setVisibility(0);

    super.rightbutton.setVisibility(4);
    Bundle bd = this.getIntent().getExtras();
    channelType = bd.getString("channelType");
    channelId = bd.getString("channelId");
    newslist = (MyListView) findViewById(R.id.newslist);

    newsbroadcast =
        new BroadcastReceiver() {

          @Override
          public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            String jsonstring = intent.getExtras().getString("json");
            int count = intent.getExtras().getInt("count");
            JSONObject json = null;
            try {
              json = new JSONObject(jsonstring);
            } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            if (count == 0) {
              newslistdata = resolveJSON(json);
              myadapter = new MyAdapter(UnloadingNewsListrActivity.this, newslistdata);
              newslist.setAdapter(myadapter);
            } else {
              newslistdata = resolveJSON(json);
              myadapter.notifyDataSetChanged();
            }
            dlg.dismiss();
          }
        };
    i = new Intent(UnloadingNewsListrActivity.this, NewsAppService.class);
    i.putExtra(
        "url",
        InfowAppUrl.NEWSLIST
            + "channelType="
            + channelType
            + "&channelId="
            + channelId
            + "&page="
            + page
            + "&pageSize="
            + pageSize);
    i.putExtra("action", NEWS_GETNEWSLIST_ACTION);
    i.putExtra("count", count++);
    startService(i);
    newslist.setonRefreshListener(
        new OnRefreshListener() {
          @Override
          public void onRefresh() {
            new AsyncTask<Void, Void, Void>() {
              @Override
              protected Void doInBackground(Void... params) {
                try {
                  Thread.sleep(1000);
                } catch (Exception e) {
                  e.printStackTrace();
                }

                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                startService(i);
                newslist.onRefreshComplete();
              }
            }.execute();
          }
        });
    leftbutton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(UnloadingNewsListrActivity.this, NewsMasterActivity.class);
            startActivity(i);
          }
        });

    newslist.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            Intent i = new Intent(UnloadingNewsListrActivity.this, NewsDetailActivity.class);
            i.putExtra("news", newslistdata.get(arg2));
            startActivity(i);
          }
        });
  }