-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a153d46
commit 033c8f0
Showing
9 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/example/xiaobai/yynote/bean/Article.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.xiaobai.yynote.bean; | ||
|
||
|
||
public class Article { | ||
private String ArticleTitle; //标题 | ||
private String ArticleUrl; //链接地址 | ||
private String ArticleWho; //来源 | ||
private String Content; | ||
|
||
public Article(String ArticleTitle, String ArticleUrl, String ArticleWho,String Content) { | ||
this.ArticleTitle = ArticleTitle; | ||
this.ArticleUrl = ArticleUrl; | ||
this.ArticleWho = ArticleWho; | ||
this.Content=Content; | ||
} | ||
|
||
|
||
public String getArticleWho() { | ||
return ArticleWho; | ||
} | ||
|
||
public void setArticleWho(String newsTime) { | ||
this.ArticleWho = newsTime; | ||
} | ||
|
||
public String getArticleTitle() { | ||
return ArticleTitle; | ||
} | ||
|
||
public void setArticleTitle(String newsTitle) { | ||
this.ArticleTitle = newsTitle; | ||
} | ||
|
||
public String getArticleUrl() { | ||
return ArticleUrl; | ||
} | ||
public String getContents() { | ||
return Content; | ||
} | ||
public void setArticleUrl(String newsUrl) { | ||
this.ArticleUrl = newsUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/src/main/java/com/example/xiaobai/yynote/ui/Meiwen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.example.xiaobai.yynote.ui; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.TextView; | ||
|
||
import com.example.xiaobai.yynote.R; | ||
import com.example.xiaobai.yynote.bean.Article; | ||
|
||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.select.Elements; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class Meiwen extends AppCompatActivity { | ||
private Handler handler; | ||
private List<Article> newsList; | ||
private TextView textView; | ||
private TextView textView1; | ||
@SuppressLint("HandlerLeak") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
if(getSupportActionBar() !=null) { | ||
|
||
getSupportActionBar().hide(); | ||
} | ||
setContentView(R.layout.meiweneveryday); | ||
textView=(TextView)findViewById(R.id.textView2); | ||
textView1=(TextView)findViewById(R.id.textView4); | ||
getNews(); | ||
handler = new Handler() { | ||
@SuppressLint("SetTextI18n") | ||
@Override | ||
public void handleMessage(Message msg) { | ||
textView.setText("handleMessage。。。"); | ||
textView1.setText("handleMessage。。。"); | ||
if (msg.what == 1) { | ||
Article news = newsList.get(0); | ||
textView.setText(news.getArticleTitle()+"\n"+news.getArticleWho()); | ||
textView1.setText(news.getContents()); | ||
} | ||
else{ | ||
textView.setText("加载中。。。"); | ||
textView1.setText("加载中。。。"); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private void getNews(){ | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try{ | ||
int i= (int) (Math.random() * 36); | ||
textView.setText("加载中。。。"); | ||
textView1.setText("加载中。。。"); | ||
Document doc = Jsoup.connect("http://www.xiaole8.com/renshengzheli/page_"+Integer.toString(i)+".html").get(); | ||
Elements titleLinks = doc.select("ul.l2"); //解析来获取每条新闻的标题与链接地址 | ||
Elements titlelins = titleLinks.get(0).select("li"); | ||
int j= (int) (Math.random() * titlelins.size()); | ||
String uri = titlelins.get(j).select("a").attr("href"); | ||
String title = titlelins.get(j).select("a").text(); | ||
Document doc1 = Jsoup.connect(uri).get(); | ||
String mainarctile=doc1.select("div.wzcon").select("p").text(); | ||
String laiyuan=doc1.select("div.info").text(); | ||
mainarctile=mainarctile.replaceAll("<br>","\n"); | ||
Article article = new Article(title, uri,laiyuan,mainarctile); | ||
newsList.add(article); | ||
Message msg = new Message(); | ||
msg.what = 1; | ||
handler.sendMessage(msg); | ||
|
||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
}).start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/textView2" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textAlignment="center" | ||
android:textSize="18sp" | ||
android:text="标题" | ||
android:gravity="center_horizontal" /> | ||
|
||
<TextView | ||
android:id="@+id/textView4" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_below="@+id/textView2" | ||
android:text="TextView" /> | ||
|
||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters