您的位置:首页 > 移动开发 > Objective-C

Android开发-Fragment JsonObject JsonArray 综合运用-AndroidStudio

2016-09-09 16:28 561 查看








Json内容如下:
http://125.208.12.227/appceshi/Api
[{"id":"1","renwu":"\u6c88\u9633-\u5317\u4eac"},{"id":"2","renwu":"\u5317\u4eac-\u897f\u5b89"}]
http://125.208.12.227/appceshi/Api/index/che/pid/1
[{"id":"1","name":"\u5f20\u4e09","phone":"1351351351","pid":"1"}]
http://125.208.12.227/appceshi/Api/index/che/pid/2
[{"id":"2","name":"\u5386\u53f2","phone":"131513513","pid":"2"}]


AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iwanghang.fragmenttransactiondemo">

<!-- 网络权限 -->
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<!-- MainActivity 强制竖屏显示 -->
<!-- android:screenOrientation="portrait" -->

</manifest>

MainActivity.java:

package com.iwanghang.fragmenttransactiondemo;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

/**
* 实现OnItemClickListener(Item点击事件监听),OnClickListener(按钮点击事件监听)
* 刷新
* 个推
* Volley:第三方插件 主要用于post、get解析
*/

public class MainActivity extends FragmentActivity implements OnClickListener{

private LinearLayout oneLinearLayout;
private LinearLayout twoLinearLayout;
private LinearLayout threeLinearLayout;
private OneFragment oneFragment;
private TwoFragment twoFragment;
private ThreeFragment threeFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

initView();
initFragment();
showOneFragment();
}

private void initView() {
oneLinearLayout = (LinearLayout)this.findViewById(R.id.oneLinearLayout);
twoLinearLayout = (LinearLayout)this.findViewById(R.id.twoLinearLayout);
threeLinearLayout = (LinearLayout)this.findViewById(R.id.threeLinearLayout);
oneLinearLayout.setOnClickListener(this);
twoLinearLayout.setOnClickListener(this);
threeLinearLayout.setOnClickListener(this);
}

private void initFragment() {
//从 FragmentManager 获得一个FragmentTransaction的实例 :
FragmentManager fragmentManager = getSupportFragmentManager();
//FragmentTransaction对fragment进行添加,移除,替换,以及执行其他动作。
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
//每一个事务都是同时要执行的一套变化.可以在一个给定的事务中设置你想执行的所有变化,
// 使用诸如 add(), remove(), 和 replace().然后, 要给activity应用事务, 必须调用 commit().

oneFragment = new OneFragment();
twoFragment =  new TwoFragment();
threeFragment =  new ThreeFragment();
//将Fragment two设置成Fragment one的目标 Fragment 然后Fragment two就可以接收Fragment one发送的消息了
oneFragment.setTargetFragment(twoFragment, OneFragment.requestCode);
//将Fragment one设置成Fragment two的目标 Fragment 然后Fragment one就可以接收Fragment two发送的消息了
twoFragment.setTargetFragment(oneFragment, TwoFragment.requestCode);
//这样Fragment one和 Fragment two就能够实现互相通信了

fragmentTransaction.add(R.id.oneFragment_container, oneFragment);
fragmentTransaction.add(R.id.twoFragment_container,twoFragment);
fragmentTransaction.add(R.id.threeFragment_container,threeFragment);
fragmentTransaction.hide(twoFragment); // 隐藏twoFragment
fragmentTransaction.hide(threeFragment); // 隐藏threeFragment
//一定要记得提交
fragmentTransaction.commit();
}

@Override
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.oneLinearLayout:
showOneFragment();
break;
case R.id.twoLinearLayout:
showTwoFragment();
break;
case R.id.threeLinearLayout:
showThreeFragment();
break;
default:
break;
}
}

/**
* 切换到OneFragment
*/
public void showOneFragment() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.show(oneFragment);
fragmentTransaction.hide(twoFragment);
fragmentTransaction.hide(threeFragment);
//一定要记得提交
fragmentTransaction.commit();
}

/**
* 切换到TwoFragment
*/
public void showTwoFragment() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.hide(oneFragment);
fragmentTransaction.show(twoFragment);
fragmentTransaction.hide(threeFragment);
//一定要记得提交
fragmentTransaction.commit();
}

/**
* 切换到ThreeFragment
*/
public void showThreeFragment() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.hide(oneFragment);
fragmentTransaction.hide(twoFragment);
fragmentTransaction.show(threeFragment);
//一定要记得提交
fragmentTransaction.commit();
}

}

MyData.java:

package com.iwanghang.fragmenttransactiondemo;

import java.io.Serializable;

public class MyData implements Serializable {
public int position;
public String taskId;

public int getPosition() {
return position;
}

public void setPosition(int position) {
this.position = position;
}

public String getTaskId() {
return taskId;
}

public void setTaskId(String taskId) {
this.taskId = taskId;
}
}

Volley4Json.java:

package com.iwanghang.fragmenttransactiondemo;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;

public class Volley4Json {

public static Context context;
public Volley4Json(Context context){
this.context = context;
}

/**
* 获取Json
*/
public static void getJsonResult(final VolleyCallBack volleyCallBack) {
// 初始化一个请求队列
RequestQueue requestQueue = Volley.newRequestQueue(context);
// json串: http://www.ytiantuan.com//api.php/index/index.html //String jsonUrl = "http://api.zsreader.com/v2/pub/channel/list?&page=1&tp=1&size=20";
String jsonUrl = "http://125.208.12.227/appceshi/Api";
// 根据给定的URL新建一个请求

/**
* JsonArrayRequest
*/
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(jsonUrl, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
// 在这里操作UI组件是安全的,因为响应返回时这个函数会被post到UI线程来执行
// 在这里尽情蹂躏响应的response。

volleyCallBack.onSuccess(response);

//成功的回调
//System.out.println("成功返回:"+ response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// 出错了怎么办?凉拌!并且在这里拌。
System.out.println("发生了一个错误!");
error.printStackTrace();
}
});

/**
* JsonObjectRequest
*/
//        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, jsonUrl, null, new Response.Listener<JSONObject>() {
//            @Override
//            public void onResponse(JSONObject response) {
//                // 在这里操作UI组件是安全的,因为响应返回时这个函数会被post到UI线程来执行
//                // 在这里尽情蹂躏响应的response。
//
//                volleyCallBack.onSuccess(response);
//
//                //成功的回调
//                //System.out.println("成功返回:"+ response.toString());
//            }
//        }, new Response.ErrorListener(){
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                // 出错了怎么办?凉拌!并且在这里拌。
//                System.out.println("发生了一个错误!");
//                error.printStackTrace();
//            }
//        });

// 把这个请求加入请求队列
requestQueue.add(jsonArrayRequest);
}

/**
* 获取Json 任务列表
*/
public static void getJsonResultTaskList(final VolleyCallBack volleyCallBack) {
// 初始化一个请求队列
RequestQueue requestQueue = Volley.newRequestQueue(context);
// json串: http://www.ytiantuan.com//api.php/index/index.html //String jsonUrl = "http://api.zsreader.com/v2/pub/channel/list?&page=1&tp=1&size=20";
String jsonUrl = "http://125.208.12.227/appceshi/Api";
// 根据给定的URL新建一个请求

/**
* JsonArrayRequest
*/
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(jsonUrl, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
// 在这里操作UI组件是安全的,因为响应返回时这个函数会被post到UI线程来执行
// 在这里尽情蹂躏响应的response。

volleyCallBack.onSuccess(response);

//成功的回调
//System.out.println("成功返回:"+ response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// 出错了怎么办?凉拌!并且在这里拌。
System.out.println("发生了一个错误!");
error.printStackTrace();
}
});

// 把这个请求加入请求队列
requestQueue.add(jsonArrayRequest);
}

/**
* 获取Json 任务详情
*/
public static void getJsonResultTaskDetails(final VolleyCallBack volleyCallBack) {
// 初始化一个请求队列
RequestQueue requestQueue = Volley.newRequestQueue(context);
String jsonUrl = "http://125.208.12.227/appceshi/Api/index/che/pid/1";
// 根据给定的URL新建一个请求

/**
* JsonArrayRequest
*/
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(jsonUrl, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
// 在这里操作UI组件是安全的,因为响应返回时这个函数会被post到UI线程来执行
// 在这里尽情蹂躏响应的response。

volleyCallBack.onSuccess(response);

//成功的回调
//System.out.println("成功返回:"+ response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// 出错了怎么办?凉拌!并且在这里拌。
System.out.println("发生了一个错误!");
error.printStackTrace();
}
});

// 把这个请求加入请求队列
requestQueue.add(jsonArrayRequest);
}

/**
* VolleyCallback
*/
public interface VolleyCallBack{
//void onSuccess(JSONObject result);
void onSuccess(JSONArray result);
}
}

OneFragment.java:

package com.iwanghang.fragmenttransactiondemo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
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.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
* 实现OnItemClickListener(Item点击事件监听),OnClickListener(按钮点击事件监听)
*/

public class OneFragment extends Fragment implements OnItemClickListener {

/**
* item
*/
private ListView listViewTask;
private List<String> list;
private LayoutInflater inflater;
private TaskAdapter taskAdapter;

/**
* MainActivity
*/
private MainActivity mainActivity;

/**
* Json
*/
private String title;
private Volley4Json volley4Json;

/**
* 传值
*/
public static int requestCode = 0;
public static String key = "OneFragment.key";

/**
* 数组 用于存放taskId
* 数组赋值 taskIdArray[i] 在解析Json并list.add时赋值
* 数组取值 taskIdArray[position] 在onItemClick并data.setTaskId时取值
*/
String[] taskIdArray = new String[100];

//onAttach(),当fragment被绑定到activity时被调用(Activity会被传入.).
@Override
public void onAttach(Context context) {
super.onAttach(context);
mainActivity = (MainActivity) context;
}

//onCreateView(),创建和fragment关联的view hierarchy时调用.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

/**
* 实例化volley4Json
*/
volley4Json = new Volley4Json(mainActivity);
/**
* UI组件初始化
*/
View view = inflater.inflate(R.layout.fragment_one,null);
/**
* item初始化
*/
listViewTask = (ListView) view.findViewById(R.id.listViewTask);
/**
* 解析Json
*/
list = new ArrayList<String>();
volley4Json.getJsonResultTaskList(new Volley4Json.VolleyCallBack() {
@Override
/**
* JSONObject
*/
//public void onSuccess(JSONObject result) {
/**
* JSONArray
*/
public void onSuccess(JSONArray result) {
System.out.println(result.toString());
/**
* JSONObject
* 解析Json中的标题 并设置到 list
* 以下对应 http://api.zsreader.com/v2/pub/channel/list?&page=1&tp=1&size=20 */
//          try {
//             JSONArray jsonArray = result.getJSONArray("data");
//             for (int i = 0; i < jsonArray.length(); i++) {
//                JSONObject obj2 = jsonArray.getJSONObject(i);
//                Log.e("TAG", obj2.getString("title"));
//                title = obj2.getString("title");
//                list.add(i + " . " + title);
//             }
//             taskAdapter = new TaskAdapter();
//             listViewTask.setAdapter(taskAdapter);
//          } catch (JSONException e) {
//             e.printStackTrace();
//          }
/**
* JSONArray
* 解析Json中的标题 并设置到 list
* 以下对应 http://125.208.12.227/appceshi/Api */
try {
JSONArray jsonArray = new JSONArray(result.toString());
System.out.println("jsonArray.toString() = " + jsonArray.toString());
System.out.println("jsonArray.length() = " + jsonArray.length());
for(int i=0;i<jsonArray.length();i++)
{
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.e("TAG", jsonObject.getString("id"));
String taskId = jsonObject.getString("id");
Log.e("TAG", jsonObject.getString("renwu"));
String renwu = jsonObject.getString("renwu");
list.add("taskId =  " + taskId + " , renwu = " + renwu);
taskIdArray[i]=taskId;
}
taskAdapter = new TaskAdapter();
listViewTask.setAdapter(taskAdapter);
} catch (JSONException e) {
e.printStackTrace();
}

}
});

/**
* Item点击事件监听
*/
listViewTask.setOnItemClickListener(this);

return view;
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

MyData data = new MyData();
data.setPosition(position);
data.setTaskId(taskIdArray[position]);
Intent intent = new Intent();
intent.putExtra(key, data);
//用于发送消息给Fragment two
getTargetFragment().onActivityResult(requestCode, Activity.RESULT_OK, intent);

mainActivity.showTwoFragment();
}

public class TaskAdapter extends BaseAdapter {
public TaskAdapter() {
super();
inflater = LayoutInflater.from(mainActivity);
}

@Override
public int getCount() {
return list.size();
}

@Override
public Object getItem(int position) {
return list.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = inflater.inflate(R.layout.item_task_list, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.content = (TextView) view.findViewById(R.id.textView_task);
view.setTag(viewHolder);
}
ViewHolder viewHolder = (ViewHolder) view.getTag();
viewHolder.content.setText(list.get(position));
return view;
}
}

private class ViewHolder {
private TextView content;
}

}

TwoFragment.java:

package com.iwanghang.fragmenttransactiondemo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
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.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/*
* 用于实现Fragment通信的例子
* 定义了一个TextView用来显示Fragment one发过来的信息
* 定义了一个EditText用力啊输入发送给Fragment one的内容
* 定义了一个Button用来触发发送消息的事件
* 定义了一个MyData 序列化对象用来存储数据
* */

public class TwoFragment extends Fragment {

private View view;
private int position;
private TextView twoFragmentText;

public static int requestCode = 1;
public static String key = "TwoFragment.key";

private TextView taskPassenger;
private TextView taskPhone;
private TextView taskPhone2;
private TextView taskPhone3;
private TextView taskRemarks;
private TextView taskRemarks2;
private TextView taskRemarks3;

/**
* MainActivity
*/
private static MainActivity mainActivity;

//onAttach(),当fragment被绑定到activity时被调用(Activity会被传入.).
@Override
public void onAttach(Context context) {
super.onAttach(context);
mainActivity = (MainActivity) context;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

System.out.println("TwoFragment onCreateView");

view = inflater.inflate(R.layout.fragment_two, container,false);

twoFragmentText = (TextView) view.findViewById(R.id.twoFragmentText);
twoFragmentText.setText("noTask");

return view;
}

//该方法用来接收 Fragment one发送过来的消息
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if( resultCode != Activity.RESULT_OK)
return ;
if( requestCode == OneFragment.requestCode)
{
//       MyData mydata = (MyData) data.getSerializableExtra(OneFragment.key);
//       System.out.println("TwoFragment mydata = " + mydata.toString());
//       String positionString = String.valueOf(mydata.getPosition());
//       System.out.println("TwoFragment positionString = " + positionString);
//
//       twoFragmentText = (TextView) view.findViewById(R.id.twoFragmentText);
//       twoFragmentText.setText(positionString);

MyData mydata = (MyData) data.getSerializableExtra(OneFragment.key);
System.out.println("TwoFragment mydata = " + mydata.toString());
String taskId = mydata.getTaskId();
System.out.println("TwoFragment taskId = " + taskId);

twoFragmentText = (TextView) view.findViewById(R.id.twoFragmentText);
twoFragmentText.setText("taskId = " + taskId);

taskPassenger = (TextView) view.findViewById(R.id.taskPassenger);
taskPhone = (TextView) view.findViewById(R.id.taskPhone);
taskPhone2 = (TextView) view.findViewById(R.id.taskPhone2);
taskPhone3 = (TextView) view.findViewById(R.id.taskPhone3);
taskRemarks = (TextView) view.findViewById(R.id.taskRemarks);
taskRemarks2 = (TextView) view.findViewById(R.id.taskRemarks2);
taskRemarks3 = (TextView) view.findViewById(R.id.taskRemarks3);

taskPassenger.setText("");
taskPhone.setText("");
taskPhone2.setText("");
taskPhone3.setText("");
taskRemarks.setText("");
taskRemarks2.setText("");
taskRemarks3.setText("");

/**
* 解析Json
*/
getJsonResultTaskDetails(taskId);

}
}

/**
* getJsonResultTaskDetails
* 解析Json 任务详情
* "http://125.208.12.227/appceshi/Api/index/che/pid/" + taskId
* (String taskId)
*/

/**
* 获取Json 任务详情
*/
public void getJsonResultTaskDetails(String taskId) {
// 初始化一个请求队列
RequestQueue requestQueue = Volley.newRequestQueue(mainActivity);
String jsonUrl = "http://125.208.12.227/appceshi/Api/index/che/pid/" + taskId;
//String jsonUrl = "http://125.208.12.227/appceshi/Api";
// 根据给定的URL新建一个请求

/**
* JsonArrayRequest
*/
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(jsonUrl, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
// 在这里操作UI组件是安全的,因为响应返回时这个函数会被post到UI线程来执行
// 在这里尽情蹂躏响应的response。

System.out.println(response.toString());

try {
JSONArray jsonArray = new JSONArray(response.toString());
String name = null;
String phone = null;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.e("TAG", jsonObject.getString("name"));
name = jsonObject.getString("name");
Log.e("TAG", jsonObject.getString("phone"));
phone = jsonObject.getString("phone");
}
taskPassenger.setText(name);
taskPhone.setText(phone);
taskPhone2.setText(phone);
taskPhone3.setText(phone);
taskRemarks.setText(name + "+++" + phone);
taskRemarks2.setText(name + "+++" + phone);
taskRemarks3.setText(name + "+++" + phone);
} catch (JSONException e) {
e.printStackTrace();
}

//成功的回调
//System.out.println("成功返回:"+ response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// 出错了怎么办?凉拌!并且在这里拌。
System.out.println("发生了一个错误!");
error.printStackTrace();
}
});

// 把这个请求加入请求队列
requestQueue.add(jsonArrayRequest);
}

}

ThreeFragment.java:

package com.iwanghang.fragmenttransactiondemo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class ThreeFragment extends Fragment {

private View rootView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(container==null)
return null;
rootView = inflater.inflate(R.layout.fragment_three, container,false);

return rootView;
}

}

activity_main.xml:

<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"
android:orientation="vertical"
tools:context=".MainActivity" >

<FrameLayout
android:id="@+id/emptyFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonList">
</FrameLayout>

<FrameLayout
android:id="@+id/oneFragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonList">
</FrameLayout>

<FrameLayout
android:id="@+id/twoFragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonList">
</FrameLayout>

<FrameLayout
android:id="@+id/threeFragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonList">
</FrameLayout>

<LinearLayout
android:id="@+id/buttonList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >

<!--android:id="@+id/oneLinearLayout"-->
<LinearLayout
android:id="@+id/oneLinearLayout"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_height="50dp">
<ImageView
android:id="@+id/imageView_renwuliebiao"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/page" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="第一页"
android:textSize="20dp"
android:textColor="#000000"/>
</LinearLayout>

<!--android:id="@+id/rbAddress"-->
<LinearLayout
android:id="@+id/twoLinearLayout"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_height="50dp">
<ImageView
android:id="@+id/imageView_renwuliebiao2"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/page" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="第二页"
android:textSize="20dp"
android:textColor="#000000"/>
</LinearLayout>

<!--android:id="@+id/threeLinearLayout"-->
<LinearLayout
android:id="@+id/threeLinearLayout"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_height="50dp">
<ImageView
android:id="@+id/imageView_renwuliebiao3"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/page" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="第三页"
android:textSize="20dp"
android:textColor="#000000"/>
</LinearLayout>

</LinearLayout>

</RelativeLayout>

fragment_one.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="Fragment One"-->
<!--android:textSize="20sp"-->
<!--android:textColor="#000000"-->
<!--android:background="#FF00FF"/>-->

<!-- 标题栏 -->
<LinearLayout
android:id="@+id/title_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text=""
android:textSize="18sp"
android:textColor="#1016c2" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/tanhao"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="任务列表"
android:textSize="25sp"
android:textColor="#5EAB25"/>
</LinearLayout>

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listViewTask"
android:layout_centerHorizontal="true"
android:layout_below="@+id/title_linearLayout" />

</RelativeLayout>

fragment_three.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Fragment Three"
android:textSize="20sp"
android:textColor="#000000"
android:background="#0000FF"/>

</LinearLayout>

fragment_two.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!-- 标题栏 -->
<LinearLayout
android:id="@+id/title_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text=""
android:textSize="18sp"
android:textColor="#1016c2" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/tanhao"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="任务详情"
android:textSize="25sp"
android:textColor="#5EAB25"/>
</LinearLayout>

<TextView
android:id="@+id/twoFragmentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment Two"
android:textSize="20sp"
android:textColor="#000000"
android:background="#FF0000"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
android:padding="10dip">
<TextView
android:id="@+id/taskPassenger"
android:text="乘车人:XXX"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/taskPhone"
android:text="电话:13800138000"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/taskPhone2"
android:text="电话2:13800138000"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/taskPhone3"
android:text="电话3:13800138000"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/taskRemarks"
android:text="任务说明1:138001380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/taskRemarks2"
android:text="任务说明2:138001380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/taskRemarks3"
android:text="任务说明3:138001380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</LinearLayout>

item_task_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="16dp">

<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/textView_task"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="中街 到 青年大街" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/textView_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="查看详情" />
</LinearLayout>

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息