首页
SubMainFragment.java
package com.example.smartcity.fragment.subway;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.example.smartcity.R;
import com.example.smartcity.activity.subway.LinesActivity;
import com.example.smartcity.activity.subway.LocationActivity;
import com.example.smartcity.activity.subway.NoticeActivity;
import com.example.smartcity.activity.subway.OperationActivity;
import com.example.smartcity.activity.subway.SiteActivity;
import com.example.smartcity.adpter.SuperBase;
import com.example.smartcity.adpter.SuperPages;
import com.example.smartcity.bean.ColumnInfo;
import com.example.smartcity.http.initSubwayHttp;
import com.example.smartcity.utils.GetNetImage;
import java.util.ArrayList;
import static com.example.smartcity.utils.CacheUtils.subwayRotation;
import static com.example.smartcity.utils.ConstantsUtils.SUBWAY_IMG_WHAT;
public class SubMainFragment extends Fragment {
private ImageView mBack;
private TextView mTitle;
private ImageView mCityLocation;
private TextView mCityWeather;
private ViewPager mSubwayViewpager;
private RadioGroup mSubwayRg;
private ListView mSubwayColumn;
Handler handler = new Handler(Looper.myLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case SUBWAY_IMG_WHAT:
loadSubwayRotation();
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sub_main, container, false);
initView(view);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
initData();
loadColumn();//设置栏目
}
//重载
@Override
public void onResume() {
super.onResume();
//改变地理位置
if (LocationActivity.name==null){
mTitle.setText("北京市");//默认显示地理位置
}
mTitle.setText(LocationActivity.name);
}
//设置地铁轮播图
public void loadSubwayRotation() {
SuperPages superPages = new SuperPages(subwayRotation.getRows().size(), mSubwayRg, getContext()) {
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView = new ImageView(getContext());
new GetNetImage(getContext(), subwayRotation.getRows().get(position).getAdvImg(), imageView);
container.addView(imageView);
return imageView;
}
};
mSubwayViewpager.setAdapter(superPages);
mSubwayRg.check(0);
mSubwayViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
mSubwayRg.check(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
//设置栏目
public void loadColumn() {
//设置假数据
ColumnInfo columnInfo1 = new ColumnInfo();
ColumnInfo columnInfo2 = new ColumnInfo();
ColumnInfo columnInfo3 = new ColumnInfo();
ColumnInfo columnInfo4 = new ColumnInfo();
columnInfo1.setIcon(R.drawable.ic_location);
columnInfo1.setName("站点查询");
columnInfo2.setIcon(R.drawable.ic_location);
columnInfo2.setName("线路查询");
columnInfo3.setIcon(R.drawable.ic_location);
columnInfo3.setName("乘车须知");
columnInfo4.setIcon(R.drawable.ic_location);
columnInfo4.setName("运营公告");
ArrayList<ColumnInfo> columnInfos = new ArrayList<>();
columnInfos.add(columnInfo1);
columnInfos.add(columnInfo2);
columnInfos.add(columnInfo3);
columnInfos.add(columnInfo4);
SuperBase superBase = new SuperBase(columnInfos.size()) {
private ImageView mColumnIcon;
private TextView mColumnName;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_column, parent, false);
mColumnIcon = (ImageView) convertView.findViewById(R.id.column_icon);
mColumnName = (TextView) convertView.findViewById(R.id.column_name);
mColumnIcon.setBackgroundResource(columnInfos.get(position).getIcon());
mColumnName.setText(columnInfos.get(position).getName());
return convertView;
}
};
mSubwayColumn.setAdapter(superBase);
mSubwayColumn.setOnItemClickListener(new SubwayColumnItemClick());
}
//栏目点击事件
class SubwayColumnItemClick implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
Intent intentSite = new Intent(getContext(), SiteActivity.class);
startActivity(intentSite);
break;
case 1:
Intent intentLinesImg = new Intent(getContext(), LinesActivity.class);
startActivity(intentLinesImg);
break;
case 2:
Intent intentNotice = new Intent(getContext(), NoticeActivity.class);
startActivity(intentNotice);
break;
case 3:
Intent intentOperation = new Intent(getContext(), OperationActivity.class);
startActivity(intentOperation);
break;
}
}
}
//初始化数据
private void initData() {
new initSubwayHttp(handler).subwayRotationData();
//返回
mBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
//跳转选择城市
mCityLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), LocationActivity.class);
startActivity(intent);
}
});
}
//初始化视图
public void initView(View view) {
mBack = (ImageView) view.findViewById(R.id.back);
mTitle = (TextView) view.findViewById(R.id.title);
mCityLocation = (ImageView) view.findViewById(R.id.city_location);
mCityWeather = (TextView) view.findViewById(R.id.city_weather);
mSubwayViewpager = (ViewPager) view.findViewById(R.id.subway_viewpager);
mSubwayRg = (RadioGroup) view.findViewById(R.id.subway_rg);
mSubwayColumn = (ListView) view.findViewById(R.id.subway_column);
}
}
fragment_sub_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".fragment.subway.SubMainFragment"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_back_s"
android:layout_gravity="center"
android:layout_marginLeft="20dp"/>
<LinearLayout
android:layout_width="180dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="北京市"
android:textSize="25dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="70dp"/>
<ImageView
android:id="@+id/city_location"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_location"
android:layout_marginTop="17dp"/>
</LinearLayout>
<TextView
android:id="@+id/city_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23℃"
android:textSize="20dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="70dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#c7c7c7"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/subway_viewpager"
android:layout_width="match_parent"
android:layout_height="180dp"/>
<RadioGroup
android:id="@+id/subway_rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="170dp"
android:layout_marginTop="145dp"
android:orientation="horizontal" />
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="栏目"/>
<ListView
android:id="@+id/subway_column"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"/>
</LinearLayout>
乘车码
SubRideFragment.java
package com.example.smartcity.fragment.subway;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.R;
import com.example.smartcity.activity.subway.ReceiveClauseActivity;
import com.example.smartcity.activity.user.LoginActivity;
import com.example.smartcity.utils.CacheUtils;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import java.util.Hashtable;
import static com.example.smartcity.utils.KeyUtils.TOKEN;
import static com.example.smartcity.utils.KeyUtils.TO_RECEIVE;
public class SubRideFragment extends Fragment {
private ImageView mBack;
private TextView mTitle;
private Button mReceive;
private ImageView mCode;
private Button mCancel;
private String token;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sub_ride, container, false);
mBack = (ImageView) view.findViewById(R.id.back);
mTitle = (TextView) view.findViewById(R.id.title);
mReceive = (Button) view.findViewById(R.id.receive);
mCode = (ImageView) view.findViewById(R.id.code);
mCancel = (Button) view.findViewById(R.id.cancel);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
}
//重载
@Override
public void onResume() {
super.onResume();
token = CacheUtils.getString(getContext(), TOKEN);//取出token
//判断是否领取乘车卡了
if (CacheUtils.getBoolean(getContext(), TO_RECEIVE) && !token.isEmpty()) {
mReceive.setVisibility(View.GONE);
mCode.setVisibility(View.VISIBLE);
mCancel.setVisibility(View.VISIBLE);
createCode();//生成二维码
}else {
mCode.setVisibility(View.GONE);
mCancel.setVisibility(View.GONE);
mReceive.setVisibility(View.VISIBLE);
}
initData();
}
//生成二维码
public void createCode(){
//获取imageView的宽高
int width = 300;
int height = 300;
//生成二维码
try {
String content = "乘车码";
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//图像数据转换,使用了矩阵转换
BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);
int[] pixels = new int[width * height];
//下面这里按照二维码的算法,逐个生成二维码的图片,
//两个for循环是图片横列扫描的结果
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * width + x] = 0xff000000;
} else {
pixels[y * width + x] = 0xffffffff;
}
}
}
//生成二维码图片的格式,使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
//显示到我们的ImageView上面
mCode.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
}
//初始化
public void initData() {
mReceive.setOnClickListener(new ReceiveClick());
mCancel.setOnClickListener(new CancelClick());
}
//注销乘车卡
class CancelClick implements View.OnClickListener{
@Override
public void onClick(View v) {
mCode.setVisibility(View.GONE);
mCancel.setVisibility(View.GONE);
mReceive.setVisibility(View.VISIBLE);
//清除缓存
CacheUtils.clearBoolean(getContext(), TO_RECEIVE);
Toast.makeText(getContext(),"乘车卡已注销!",Toast.LENGTH_SHORT).show();
}
}
//领取乘车卡
class ReceiveClick implements View.OnClickListener {
@Override
public void onClick(View v) {
//判断是否登陆了
if (token.isEmpty()) {
Intent intentLogin = new Intent(getContext(), LoginActivity.class);
startActivity(intentLogin);
Toast.makeText(getContext(),"请先登录!",Toast.LENGTH_SHORT).show();
} else {
Intent intentClause = new Intent(getContext(), ReceiveClauseActivity.class);
startActivity(intentClause);
}
}
}
}
fragment_sub_ride.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".fragment.subway.SubRideFragment"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_back_s"
android:layout_gravity="center"
android:layout_marginLeft="20dp"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="乘车码"
android:textSize="25dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="100dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#c7c7c7"/>
<Button
android:id="@+id/receive"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="领取乘车卡"
android:layout_gravity="center"
android:layout_marginTop="200dp"/>
<ImageView
android:id="@+id/code"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_marginTop="150dp"
android:visibility="gone"/>
<Button
android:id="@+id/cancel"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="注 销"
android:textColor="@color/white"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:visibility="gone"/>
</LinearLayout>
线路图
SubLinesFragment.java
package com.example.smartcity.fragment.subway;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.smartcity.R;
import com.example.smartcity.http.initSubwayHttp;
import com.example.smartcity.utils.GetNetImage;
import static com.example.smartcity.utils.CacheUtils.linesImg;
import static com.example.smartcity.utils.ConstantsUtils.LINES_IMG_WHAT;
public class SubLinesFragment extends Fragment {
private ImageView mBack;
private TextView mTitle;
private ImageView mLinesImg;
Handler handler = new Handler(Looper.myLooper()){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case LINES_IMG_WHAT:
loadLinesImg();
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sub_lines, container, false);
mBack = (ImageView) view.findViewById(R.id.back);
mTitle = (TextView) view.findViewById(R.id.title);
mLinesImg = (ImageView) view.findViewById(R.id.lines_img);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
initData();
}
//设置线路图
public void loadLinesImg(){
new GetNetImage(getContext(),linesImg.getData().getImgUrl(),mLinesImg);
}
//初始化数据
public void initData(){
new initSubwayHttp(handler).linesImgData();
}
}
fragment_sub_lines.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".fragment.subway.SubLinesFragment"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_back_s"
android:layout_gravity="center"
android:layout_marginLeft="20dp"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="线路查询"
android:textSize="25dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="90dp"/>
</LinearLayout>
<ImageView
android:id="@+id/lines_img"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
android:layout_marginTop="200dp"/>
</LinearLayout>
我的
SubPersonFragment.java
package com.example.smartcity.fragment.subway;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.example.smartcity.R;
import com.example.smartcity.activity.subway.AboutActivity;
import com.example.smartcity.activity.subway.LostFoundActivity;
import com.example.smartcity.activity.subway.NoticeActivity;
import com.example.smartcity.activity.user.LoginActivity;
import com.example.smartcity.adpter.SuperBase;
import com.example.smartcity.bean.ColumnInfo;
import com.example.smartcity.http.initHomeHttp;
import com.example.smartcity.info.GetPersonInfo;
import com.example.smartcity.utils.CacheUtils;
import java.util.ArrayList;
import static com.example.smartcity.utils.ConstantsUtils.GET_INFO_WHAT;
import static com.example.smartcity.utils.KeyUtils.TOKEN;
public class SubPersonFragment extends Fragment {
private ImageView mBack;
private TextView mTitle;
private ImageView mPersonHeadImg;
private TextView mPersonNickname;
private TextView mUsernameTitle;
private TextView mPersonUsername;
private ListView mSubwayPersonColumn;
private String token;
private GetPersonInfo getPersonInfo;
Handler handler = new Handler(Looper.myLooper()){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case GET_INFO_WHAT:
getPersonInfo = (GetPersonInfo) msg.obj;
showInfo();
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sub_person, container, false);
mBack = (ImageView) view.findViewById(R.id.back);
mTitle = (TextView) view.findViewById(R.id.title);
mPersonHeadImg = (ImageView) view.findViewById(R.id.person_head_img);
mPersonNickname = (TextView) view.findViewById(R.id.person_nickname);
mUsernameTitle = (TextView) view.findViewById(R.id.username_title);
mPersonUsername = (TextView) view.findViewById(R.id.person_username);
mSubwayPersonColumn = (ListView) view.findViewById(R.id.subway_person_column);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
loadColumn();
}
@Override
public void onResume() {
super.onResume();
token = CacheUtils.getString(getContext(), TOKEN);//获取token
if (!token.isEmpty()){
new initHomeHttp(handler).getInfoData(getContext(),token);
}
else {
mPersonUsername.setVisibility(View.GONE);
mUsernameTitle.setVisibility(View.GONE);
mPersonNickname.setText("立即登录");
mPersonNickname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), LoginActivity.class);
startActivity(intent);
}
});
}
}
//显示用户信息
public void showInfo(){
//获取用户信息
mPersonUsername.setVisibility(View.VISIBLE);
mUsernameTitle.setVisibility(View.VISIBLE);
mPersonUsername.setText(getPersonInfo.getUser().getUserName());
mPersonNickname.setText(getPersonInfo.getUser().getNickName());
}
//设置栏目
public void loadColumn() {
//设置假数据
ColumnInfo columnInfo1 = new ColumnInfo();
ColumnInfo columnInfo2 = new ColumnInfo();
ColumnInfo columnInfo3 = new ColumnInfo();
ColumnInfo columnInfo4 = new ColumnInfo();
ColumnInfo columnInfo5 = new ColumnInfo();
columnInfo1.setIcon(R.drawable.ic_location);
columnInfo1.setName("失物招领");
columnInfo2.setIcon(R.drawable.ic_location);
columnInfo2.setName("乘车须知");
columnInfo3.setIcon(R.drawable.ic_location);
columnInfo3.setName("地铁热线");
columnInfo4.setIcon(R.drawable.ic_location);
columnInfo4.setName("关于我们");
columnInfo5.setIcon(R.drawable.ic_location);
columnInfo5.setName("退出城市地铁");
ArrayList<ColumnInfo> columnInfos = new ArrayList<>();
columnInfos.add(columnInfo1);
columnInfos.add(columnInfo2);
columnInfos.add(columnInfo3);
columnInfos.add(columnInfo4);
columnInfos.add(columnInfo5);
SuperBase superBase = new SuperBase(columnInfos.size()) {
private ImageView mColumnIcon;
private TextView mColumnName;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_column, parent, false);
mColumnIcon = (ImageView) convertView.findViewById(R.id.column_icon);
mColumnName = (TextView) convertView.findViewById(R.id.column_name);
mColumnIcon.setBackgroundResource(columnInfos.get(position).getIcon());
mColumnName.setText(columnInfos.get(position).getName());
return convertView;
}
};
mSubwayPersonColumn.setAdapter(superBase);
mSubwayPersonColumn.setOnItemClickListener(new SubwayPersonColumnItemClick());
}
//条目点击事件
class SubwayPersonColumnItemClick implements android.widget.AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
Intent intentLost = new Intent(getContext(), LostFoundActivity.class);
startActivity(intentLost);
break;
case 1:
Intent intentNotice = new Intent(getContext(), NoticeActivity.class);
startActivity(intentNotice);
break;
case 2:
String phoneNum = "07712201000";
Intent intentPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+phoneNum));
startActivity(intentPhone);
break;
case 3:
Intent intentAbout = new Intent(getContext(), AboutActivity.class);
startActivity(intentAbout);
break;
case 4:
getActivity().finish();//退出地铁
break;
}
}
}
}
fragment_sub_person.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".fragment.subway.SubPersonFragment"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_back_s"
android:layout_gravity="center"
android:layout_marginLeft="20dp"/>
<LinearLayout
android:layout_width="180dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="个人中心"
android:textSize="25dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="70dp"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#c7c7c7"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="horizontal">
<ImageView
android:id="@+id/person_head_img"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/ic_head_img"
android:layout_gravity="center"
android:layout_marginLeft="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/person_nickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="立即登录"
android:textSize="20dp"
android:layout_marginTop="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/username_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:"
android:layout_marginTop="10dp"
android:visibility="gone"/>
<TextView
android:id="@+id/person_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="111"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="栏目"
android:layout_marginLeft="10dp"/>
<ListView
android:id="@+id/subway_person_column"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:layout_marginTop="10dp"/>
</LinearLayout>