SlideShare a Scribd company logo
1 of 16
新聞 App 的兩三事
分工
• 後端Solr
• 前端
• Android
• IOS
• 文案
理想流程
先拉一個最原始的layout
->和Server API做串連
->需要的資訊都能串到View
->把layout修的很漂亮,非常滿意
->上架Google Play
實際狀況
先拉一個最原始的layout
->塞假資料
->串連API+討論+調整sample data
->後端的新聞不一定撈到所有column, parse錯誤
->自己做假資料
->討論UI,有什麼資料適合呈現呢
->調整UI
->好像不是所有東西都適合放上去
->參考各App或網站的呈現方式->裁剪UI->回調整UI
->上架Google Play
串接API的方法 org.apache.http
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(solrUrl);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) { builder.append(line); }
Parse Json Data 方法 Gson
public class News{
private int likes;
private int dislikes;
private int threat_level;
private String category;
private String title;
private String snippet;
}
{ "like": 22, "dislike": 11, "threat_level": 3,
"category": "policity", "title": "拚到底?黃景
泰:對選情仍樂觀", "snippet": "國民黨中央
連日來「勸退」基隆市長參選人黃景泰的聲
浪不斷,台北市長郝龍斌、新北市長朱立倫
輪番表態,要黃退選。"}
Gson gson = new Gson();
News news = gson.fromJson(jsonNews, News.class);
Parse Json Array
Gson gson = new Gson();
Type listType = new TypeToken<List<News>>(){}.getType();
ArrayList<News> newsList = gson.fromJson(jsonNews, listType);
[
{ "like": 22, "dislike": 11, "threat_level": 3, "category":
"policity", "title": "拚到底?黃景泰:對選情仍樂觀",
"snippet": "國民黨中央連日來「勸退」基隆市長參選人黃景
泰的聲浪不斷,台北市長郝龍斌、新北市長朱立倫輪番表
態,要黃退選。"}
{ "like": 22, "dislike": 11, "threat_level": 3, "category":
"policity", "title": "拚到底?黃景泰:對選情仍樂觀",
"snippet": "國民黨中央連日來「勸退」基隆市長參選人黃景
泰的聲浪不斷,台北市長郝龍斌、新北市長朱立倫輪番表
態,要黃退選。"}
]
• JSONObject jsonObject = new JSONObject(jsonNews)
• jsonObject.get(“like”)
• JSONArray jsonArray = new JSONArray (jsonNews)
• jsonArray.get(0)
• 其他可用方法
• getString() getInt() getJSONArray() getJSONObject()
另外一種方法 org.json.JSONObject
{ "like": 22, "dislike": 11, "threat_level": 3, "category":
"policity", "title": "拚到底?黃景泰:對選情仍樂觀",
"snippet": "國民黨中央連日來「勸退」基隆市長參選人黃景
泰的聲浪不斷,台北市長郝龍斌、新北市長朱立倫輪番表
態,要黃退選。"}
其他資料對應情形
• List => ArrayList (implement List介面的class)
• Dictionary => HashMap (implement Map介面的class)
可能會碰到的狀況
• NetworkOnMainThreadException
• 解決方法
• Asyntask
• onPreExecute()
• doInBackground()
• onPostExecute()
• New Thread
無法更新UI
• Only the original thread that created a view hierarchy can touch its views.
• 解決方法
• Handler{ handleMessage(Message msg) { // ui update stuff } }
• Activity{ runOnUiThread(new Runnable() { // ui update stuff } }
UI
• 不是真的用拉的,因為Graphical layout很難用
• 理解View和Layout有哪些屬性
• 有很多 看起來沒什麼差別的參數
• Margin padding
• Layout_gravity gravity
• paddingStart paddingTop
• …………………………
最常用的元件 ListView
客製化自己的ListView
• 和後端說需要什麼資料
• 畫出個草圖
• 在自己的layout.xml加上需要的View
• 調整Adapter
• 調整layout和View參數
幾個好網站
• JSON Editor Online - view, edit and format JSON online
• www.jsoneditoronline.org
• Pttrns
• http://www.pttrns.com/
Q & A

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Android 新聞app兩三事