请问老师 在fragment里面怎么请求网络数据??
诺曼蒂克
2014-10-22
3 回答
import com.hiaio.Client.R; import com.hiaio.http.HttpUtils; import android.os.Bundle; import android.os.Handler; import android.os.Message; 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.GridView; public class OneFragment extends Fragment { private GridView gridView; private View view; private String path = "************************************"; private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { String string = (String) msg.obj; System.out.println("shuju" + string); Log.i("msgmsg", string); } }; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_1, container, false); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub String jsonString2 = HttpUtils.getData(path); System.out.println(jsonString2); Message msg = handler.obtainMessage(); msg.obj = jsonString2; handler.sendMessage(msg); } }).start(); String data = new HttpUtils().getData(path); System.out.println("fff" + data); return view; }
举报
0/150
提交
取消