Skip to content

Commit

Permalink
hzuapps#6 hzuapps#15 第六次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzming95 committed May 27, 2017
1 parent 0801216 commit 2eb5bb1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,108 @@
package edu.hzuapps.androidlabs.homework.net1414080903230;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.os.Environment;

import java.io.File;
import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;


/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link Net1414080903230_UserFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link Net1414080903230_UserFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class Net1414080903230_UserFragment extends Fragment {
TextView text;
private Handler handler=null;
private TextView textView=null;
private String da="";

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_net1414080903230__user, container, false);
handler=new Handler();

Button button = (Button) view.findViewById(R.id.button2);
text=(TextView) view.findViewById(R.id.user_content);
textView = (TextView) view.findViewById(R.id.user_content);
button.setOnClickListener(new submitOnClieckListener());
/*
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//new Thread(new GetData()).start();
new Thread(new Runnable() {
public void run() {
try {
Document doc = Jsoup.connect("https://github.com/shezhiming/android-labs-2017/blob/master/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903230/data.xml").get();
int i = 0;
Elements data = doc.select("#LC"+i);
while(!data.isEmpty()){
da += data.text();
i++;
data = doc.select("#LC"+i);
}
textView.setText(da);
}catch(IOException e){
System.out.println("in procedure, catch ArithmeticException: " + e);
}
handler.post(runnableUi);
}
}).start();
}
});
*/
return view;
}

class submitOnClieckListener implements View.OnClickListener {
@Override
public void onClick(View v) {
//本地机器部署为服务器,从本地下载a.txt文件内容在textView上显示
new Thread(){
public void run(){
try {

Document doc = Jsoup.connect("https://github.com/shezhiming/android-labs-2017/blob/master/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903230/data.xml").get();
int i = 1;
Elements data = doc.select("#LC"+i);
while(!data.isEmpty()){
da += data.text();
i++;
data = doc.select("#LC"+i);
}

//Log.d("test",da);
//textView.setText(da);
}catch(IOException e){
System.out.println("in procedure, catch ArithmeticException: " + e);
}

handler.post(runnableUi);
}
}.start();
}

}



Runnable runnableUi=new Runnable(){
@Override
public void run() {
//更新界面
textView.setText(da);

}

};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@color/aquamarine"
android:orientation="vertical">
android:background="@color/mintcream"
android:orientation="vertical"
android:id="@+id/user">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="30sp"
android:id="@+id/user_content" />

<Button
android:text="获取信息"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个页面"
android:textSize="22sp"/>
android:id="@+id/button2" />
</LinearLayout>

0 comments on commit 2eb5bb1

Please sign in to comment.