If water News Android client notes

Source: Internet
Author: User

Lesson3-Design News category Navigation UI


Arrays.xml
Define an array
string[] Categoryarray = getresources (). Get
GridView Category = new GridView (this);
Category.setnumcolumns (Gridview.auto_fit);
Category.setgravity (Gravity.center);

PX Conversion to dip format
Using the Densityutil.java tool class

Adapter
Simpleadapter
for (int i=0;i<categoryarray.length;i++)
{
HashMap
}

Horizontalscrollview


Lesson4-click Change background and text color


Small classes can be rewritten, customized, large-class internal functions, complex interfaces, not recommended to write
BindView GetView TextView
Position SetBackground GridView Custom Simpleadampter


LESSON5-News List layout information


Server information calls, using HashMap


Lesson6-Write a comment box


Image, click to EditView

Draw9patch 9.png


Lesson7-Upgrade News content UI


Viewflipper


Lesson8-Design News reply UI


Mainly for the interface layout design
Use of extensions <include> tags


Lesson9-Call the server interface to parse the news information


Request URL
Start Tomcat
Category
Loop array
if (temp = = 2)

Title
category{
}
url =?
Name value key value pair

Private final int newscount = 5;


Public
If there is an exception, use the try {} catch {}
if (RetCode = = 0)

Json
Jsonobject dataobj =
int totalnum = DataObject ()
Dynamic Update ListView in Android


LESSON10-News category display and bottom loading more


Toast
Declared as a global variable
List ArrayList

Category.
Private
Mcid = Category.get (Position). Get ("Category_title"). Getcid ();
System.out.printIn ("Ori:" +cid)
private void Getspecatenews (Mcid, mnewsdata);
Mewslist.clear ();
Simplelistadapter;
Mnewslist
Mnewsdata;
or new, or find out.
Mcid as a classification identifier
Notifydata

__ Bottom Load Button

Addfooterview (Loadview)
View Footerview = Minflater.inflate (r.layout.)
Loadmore.xml
Private Onclicklistener Loadmorelistener = new Onclicklistener ()
{
@Override
public void OnClick (View v)
{
Get the news under this section
Getspecatenews (Mcid,mnewsdata,mnewsdata.size (), false);
Notify ListView Update
Mnewslistadapter.notifydatasetchanged ();}};
Getspacatenews (Mcid, Boolen firsttime)
if (firsttime)
{}
A function is a good thing.


Lesson11-Updating UI interface and principle analysis using Asynctask asynchronous


That makes the UI change as you work
Private class Loadnewsasynctask<object, Integer, void>
{
@Override
protected void OnPreExecute (Bitmap result)
{
Mtitlebarrefresh.setvisibility (View.gone);
Mloadnewsprogress.setvisibility (view.visible);
Mloadmorebtn.settext (R.string.loadmore_txt);
}
@Override
Protect Void Doinbackground (Object ... params)
}
OnPreExecute ()

1 How to write a key in uppercase after entering lowercase
2 How to annotate a row to the beginning of a line

Toast information is put into a class, calling its arguments, making the code more friendly


Lesson12-click on the title to go to the details page


News classification to pass, information title, time, source to pass, news content through the interface to get
Thread information added to HashMap.

Global variable mcategory, local variable category

Intent.putextra ("Newsdata", mnewsdata);
Startactovity (Intent);

Java fundamentals need to be deepened

Intent.putextra ("position", posotion)
Intent Intent = Getintent ();
Bundle bundle = Intent.getextras ();

Position
Mposition = Bundle.getint ("position");
serializable =
Intent.getbundlerextra ("");
Get the information passed
TextView newsdetails_titlebar_title=

Two switching of activity

The thread is the input content, saved and displayed.


LESSON13-Loading news content asynchronously


-Fix the next news
Load news content synchronously, load news content asynchronously
The main thread of the UI is shown in TextView

Activity.runonuothread (Runnable)
View.post (Runnable)
View.postdelayed (Runnable, long)
Handler
Carbon Asynctask

Private Handlermhandler = new Handler ()
{
Getnewsbody
Newsdetails = (TextView)
Nnewsdetails.settext (html.fromhtml (msg.obg.toString ()));


What is the same or a different thread?
Loading News messages Asynchronously
Server Startup
mpostion++;
HashMap
Dynamic News and information
The view is placed in the fliper.
News back plural
Inside the titlebar.
button that is declared as global
A piece of analysis
Position<mnewsdata-1>


String newsstr = Getnewsbody ();
Private final int FINISH = 0;

handlermessage{
Mnewsdetails.settext (Html)}
}

Android Loading pictures asynchronously


LESSON14-News reply function


Mnewsreply
Ontouchlistener
Setvisibility (view.visiable)
Thread
Ret
Message
Post
Params.add (New Parameter ("Nid", mnid+ ""))

Synchttp http = new Sychttp ();
http. HttpPost (Url,params)
Android obtains location information according to the mobile phone number, according to GPs to obtain location information.
Try
{
String retstr = Http.httppost (url,params);
Jsonobject object = new Jsonobject (RETSTR);
int RetCode
Drunable
}

Focus EditText when clicked and show soft keyboard Input Method
Object.requestfocus ();
M.togglesoftinput (0, inputmethodmanager.show_implicit);
Hide IME:
M.togglesoftinput (0, inputmethodmanager.hide_not_always);


Lesson15-Show News reply information


Private listprivate void getcomments (int nid)
{
Request URL and string
String url = "Http://10.0.2.2:8080/web/getComments";
String params = "nid=" +nid+ "&startnid=0&count=10";
Synchttp synchttp = new Synchttp ();
Try
{
To
int retCode = Jsonobject.getint ("ret");
if (0==retcode)
{
Jsonobject dataObject = jsonobject.getjsonobject ("Data");
Get the number of returns
int totalnum = Dataobject.getint ("Totalnum");
if (totalnum>0)
{
Get Return News Collection
Jsonarray commslist = Dataobject.getjsonarray ("Commentslist");
for (int i=0;i<commslist.length (); i++)
{
Jsonobject Commsobject = (jsonobject) commslist.opt (i);
hashmap<string, object> HashMap = new hashmap<string, object> ();
Hashmap.put ("CID", Commsobject.getint ("CID"));
Hashmap.put ("REGIPN", commsobject.getstring ("region"));
Hashmap.put ("Ptime", Commsobject.getstring ("Ptime"));
Hashmap.put ("Content", commsobject.getstring ("content"));
Mcommsdata.add (HASHMAP);
}
}
Else
{
Toast.maketext (Commentsactivity.this, "no reply", Toast.length_long)
}
Else
{Toast.}
}
}


Lesson16-Add AD


Choose an advertising provider, an advertising alliance, to withdraw cash, such as Baidu Mobile Alliance.
Promote Android SDK
Declaration method, code way to implement advertising, instantiation, annotation description.

referencing jar Packages
Create a new folder, copy the jar package, right-click->build path->add to Build path

Configure manifest Add Permissions
Add Appsid to identify the current application ID information

Add app details activity
Create a Attrs.xml file

Path declaration for SDK Packages

No Add to Show has a delay


LESSON17-Software updates automatically


Get server-side version number-Determine if update-download update-Confirm Installation-Complete installation

Perform the update operation.
Updatemanager

XML parsing Parsexmlservice.java

Builder Construction Dialog
Get the SD card path, download the APK and put it in the download directory
File.mkdir ();
CancelUpdate
Update the progress bar information, update the UI information needs to be placed in the UI thread, placed in the handler
Make handler update the UI by judging the progress
installapk Method installation Program
Direct copy Use

Ddms interface to find mnt-sdcard-download-baidunews1.0.13.apk
Java+xml implementation


Lesson18-Custom TextView (1) Graphic mix


Customtextview.java
TextView TextView = new TextView (this);
TextView
arraylistReplication Parent Method
Public Customtextview (Context context)
{
This (context, NULL);
}

if (Type.epuals ("image"))
{
ImageView ImageView = new ImageView (mcontext);
Imageview.setlayoutparams (New Layoutprams (layoutparams.wrap_content);)
Imageview.setimageresource (R.drawable.kuka);
AddView (ImageView);
New Downloadpicthread (ImageView, Hashmap.get ("value"));

}

SetOrientation (linearlayout.vertical);


<com.szy.view.CustomTextView>

Customtextview custom = new TextView

Html.fromhtml (Source, Imagegetter, Taghandler) (must try, not tested)

Attrs.xml
Android Custom Properties
TypedArray to reference and instantiate custom XML properties
<declare-styleable name= "Customtextview" >

<attr name= "Image_width" format= "Dimension"/>
Get method, get picture width and height, 20 ' 20 "

Szy:image_width= "200dip"
The namespace of XML, the system comes with its own namespace
The name of the package
The width and height of the picture have changed
Property information
Layoutparams (New Layout)
Params.gravity = Gravity.center_horizion
Dynamic configuration, loading picture information asynchronously
View.post


Lesson19-Custom TextView (2) applies the custom component to the news client.


The custom control has flaws
Can't tell the difference between a picture or a text
News content must be returned in a fixed format
Interface information
Body
Getserverlate folder overrides one class file
ArrayList has three hashmap inside.
Segmentation of text information
The format of the picture has been fixed.
Text messages are read from the database.
for (int)
return bodylist;

Mnewsdetails


Lesson20-Program Packaging and publishing


Version testing each version of the compilation test, model testing, system rooms customized to modify I, may make the application can not be used, the need for multi-machine testing.

Install the phone driver, USB debugging enabled, you can join the real machine device to eclipse emulator device.

Can perform real-machine testing to improve efficiency.

Pack apk, sign, decompile, build.
Save the signature file, uniqueness.

Download usage and data of the Friends League statistics app




If water News Android client notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.