コード例 #1
0
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
   NewEntity entity = (NewEntity) mAdapter.getItem(position - 1);
   Intent intent = new Intent(getActivity(), BrowseActivity.class);
   intent.putExtra(BrowseActivity.EXTRA_URL, entity.getUrl());
   intent.putExtra(BrowseActivity.EXTRA_TITLE, entity.getTitle());
   startActivity(intent);
 }
コード例 #2
0
 @Override
 protected Boolean doInBackground(String... params) {
   try {
     Document doc = Jsoup.connect(params[0]).get();
     Element body = doc.body();
     Elements titleEs = body.select("td.title");
     Elements subTitleEs = body.select("td.subtext");
     int index = 1;
     if (!titleEs.isEmpty()) {
       if (mType == TYPE_REFRESH && mNews.size() > 0) {
         mNews.clear();
       }
       Iterator<Element> iterator = titleEs.iterator();
       Iterator<Element> subIt = subTitleEs.iterator();
       NewEntity entity = null;
       User user = null;
       while (iterator.hasNext()) {
         Element e = iterator.next();
         if (index % 2 == 0) {
           Element subE = subIt.next();
           Elements aTag = e.select("a");
           Elements spanTag = e.select("span.comhead");
           Elements subEa = subE.select("a");
           user = new User();
           user.setId(subEa.get(0).text());
           entity =
               new NewEntity(
                   aTag.get(0).attr("href"),
                   aTag.get(0).text(),
                   spanTag.isEmpty() ? null : spanTag.get(0).text(),
                   subE.html());
           entity.setDiscussUrl(subEa.get(1).attr("href"));
           // Log.i(LOG_TAG, entity.toString());
           mNews.add(entity);
         }
         index++;
       }
     }
     Elements more = doc.getElementsByAttributeValueStarting("href", "/x?fnid=");
     if (!more.isEmpty()) {
       mMoreURLPath = more.get(1).attr("href");
     }
     return true;
   } catch (IOException e) {
     Log.e(LOG_TAG, "", e);
     return false;
   }
 }
コード例 #3
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   ViewHolder holder;
   if (convertView == null) {
     holder = new ViewHolder();
     convertView = LayoutInflater.from(getActivity()).inflate(R.layout.news_list_item, null);
     holder.mText1 = (TextView) convertView.findViewById(android.R.id.text1);
     holder.mText2 = (TextView) convertView.findViewById(android.R.id.text2);
     convertView.setTag(holder);
   } else {
     holder = (ViewHolder) convertView.getTag();
   }
   NewEntity entity = mNews.get(position);
   holder.mText1.setText(entity.getTitle());
   holder.mText2.setText(Html.fromHtml(entity.getSubText()));
   return convertView;
 }