News
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
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:layout_marginLeft="14dp"
android:layout_marginTop="14dp"
android:layout_marginBottom="7dp"
android:text="专题" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/new_l"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:layout_marginRight="7dp"
android:layout_weight="1"
android:background="@drawable/news"
android:orientation="vertical">
<ImageView
android:scaleType="fitXY"
android:id="@+id/new_l_img"
android:layout_width="match_parent"
android:layout_height="100dp" />
<TextView
android:id="@+id/new_l_txv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="7dp"
android:ellipsize="end"
android:maxLines="2"
android:text="123" />
</LinearLayout>
<LinearLayout
android:id="@+id/new_r"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="14dp"
android:layout_weight="1"
android:background="@drawable/news"
android:orientation="vertical">
<ImageView
android:scaleType="fitXY"
android:id="@+id/new_r_img"
android:layout_width="match_parent"
android:layout_height="100dp" />
<TextView
android:id="@+id/new_r_txv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="7dp"
android:ellipsize="end"
android:maxLines="2"
android:text="123" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="14dp"
android:background="@color/huise" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="14dp"
android:orientation="horizontal">
<TextView
android:id="@+id/new_l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/new_l2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/new_l3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/new_l4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/new_l5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/new_l6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/new_linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="14dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<ListView
android:id="@+id/new_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.example.test1218.Const;
import com.example.test1218.news.NewsInfo;
import com.example.test1218.R;
import com.example.test1218.fengzhuang.Height;
import com.example.test1218.fengzhuang.Okhehe;
import com.example.test1218.news.NewsBean;
import com.example.test1218.news.NewsData;
import com.example.test1218.news.NfData;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class NewsFragment extends Fragment {
View view;
Okhehe hehe;
String qianzhui;
List<NewsBean> l1 = new ArrayList<>(), l2 = new ArrayList<>(),l3=new ArrayList<>();
TextView t1, t2, t3, t4, t5, t6;
TextView ts[] = new TextView[]{t1, t2, t3, t4, t5, t6};
int tsId[] = new int[]{R.id.new_l1, R.id.new_l2, R.id.new_l3, R.id.new_l4, R.id.new_l5, R.id.new_l6};
ListView listView;
LinearLayout linearLayout;
LinearLayout l,r;
TextView l_t,r_t;
ImageView l_i,r_i;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.news_fragment, container, false);
listView = view.findViewById(R.id.new_list);
linearLayout = view.findViewById(R.id.new_linear);
hehe = Okhehe.getInstance();
qianzhui = getActivity().getSharedPreferences("Myshujv", Context.MODE_PRIVATE)
.getString("qianzhui", "");
l=view.findViewById(R.id.new_l);
r=view.findViewById(R.id.new_r);
l_t=view.findViewById(R.id.new_l_txv);
r_t=view.findViewById(R.id.new_r_txv);
l_i=view.findViewById(R.id.new_l_img);
r_i=view.findViewById(R.id.new_r_img);
PutMyNews();
return view;
}
private void PutMyNews() {
String url = qianzhui + "/prod-api/press/press/list";
hehe.GetString(url, new Okhehe.FuncString() {
@Override
public void onResponse(String js) {
NewsData nd = new Gson().fromJson(js, NewsData.class);
l1.clear();
for (int i = 0; i < nd.getRows().size(); i++) {
l1.add(nd.getRows().get(i));
}
PutMyNF();
PutMyTwoNews(l1);
}
});
}
private void PutMyTwoNews(final List<NewsBean> newsBeans) {
l3.clear();
for (int i=0;i<newsBeans.size();i++){
if (newsBeans.get(i).getHot().equals("Y")){
l3.add(newsBeans.get(i));
}
}
Glide.with(getActivity()).load(qianzhui+newsBeans.get(0).getCover()).into(l_i);
Glide.with(getActivity()).load(qianzhui+newsBeans.get(1).getCover()).into(r_i);
l_t.setText(Html.fromHtml(newsBeans.get(0).getContent()));
r_t.setText(Html.fromHtml(newsBeans.get(1).getContent()));
l.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Const.newsBean=newsBeans.get(0);
startActivity(new Intent(getActivity(), NewsInfo.class));
}
});
r.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Const.newsBean=newsBeans.get(1);
startActivity(new Intent(getActivity(), NewsInfo.class));
}
});
}
private void PutMyNF() {
String url = qianzhui + "/prod-api/press/category/list";
hehe.GetString(url, new Okhehe.FuncString() {
@Override
public void onResponse(String js) {
final NfData nf = new Gson().fromJson(js, NfData.class);
for (int i = 0; i < ts.length; i++) {
ts[i] = view.findViewById(tsId[i]);
ts[i].setText(nf.getData().get(i).getName());
if (i == 0) {
l2.clear();
for (int s = 0; s < l1.size(); s++) {
if (l1.get(s).getType() != null) {
if (l1.get(s).getType().equals(String.valueOf(nf.getData().get(0).getId()))) {
l2.add(l1.get(s));
}
}
}
PutMyNewView(l2);
}
final int c = i;
ts[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
l2.clear();
for (int s = 0; s < l1.size(); s++) {
if (l1.get(s).getType() != null) {
if (l1.get(s).getType().equals(String.valueOf(nf.getData().get(c).getId()))) {
l2.add(l1.get(s));
}
}
}
PutMyNewView(l2);
}
});
}
}
});
}
private void PutMyNewView(final List<NewsBean> newsBeans) {
MyListAdapter adapter = new MyListAdapter(newsBeans);
listView.setAdapter(adapter);
Height ht = new Height();
ht.height(linearLayout, listView, adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Const.newsBean=newsBeans.get(i);
startActivity(new Intent(getActivity(), NewsInfo.class));
}
});
}
private class MyListAdapter extends BaseAdapter {
List<NewsBean> newsBeans;
public MyListAdapter(List<NewsBean> newsBeans) {
this.newsBeans = newsBeans;
}
@Override
public int getCount() {
return newsBeans.size();
}
@Override
public Object getItem(int i) {
return newsBeans.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View v1 = View.inflate(getActivity(), R.layout.list_style, null);
ImageView imageView = v1.findViewById(R.id.news_img);
TextView title = v1.findViewById(R.id.news_title);
TextView nr = v1.findViewById(R.id.news_nr);
TextView time = v1.findViewById(R.id.news_time);
TextView pl = v1.findViewById(R.id.news_pl);
Glide.with(getActivity()).load(qianzhui + newsBeans.get(i).getCover()).into(imageView);
title.setText(newsBeans.get(i).getTitle());
nr.setText(Html.fromHtml(newsBeans.get(i).getContent()));
time.setText(newsBeans.get(i).getPublishDate());
pl.setText(String.valueOf(newsBeans.get(i).getCommentNum()));
return v1;
}
}
}
<?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">
<ImageView
android:layout_marginLeft="14dp"
android:id="@+id/news_img"
android:layout_width="120dp"
android:layout_height="90dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:layout_marginRight="7dp"
android:background="@color/huise"
android:scaleType="fitXY" />
<LinearLayout
android:layout_marginRight="14dp"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:orientation="vertical">
<TextView
android:singleLine="true"
android:id="@+id/news_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="123"
android:textSize="18sp" />
<TextView
android:singleLine="true"
android:id="@+id/news_nr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="123" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="发布时间:"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<TextView
android:singleLine="true"
android:id="@+id/news_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="123" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="评论数量:"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<TextView
android:singleLine="true"
android:id="@+id/news_pl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="123" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
NewInfo
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/blue"
android:gravity="center"
android:text="新闻详情"
android:textColor="@color/white"
android:textSize="22sp" />
<LinearLayout
android:id="@+id/news_info_fh"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_centerVertical="true">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_marginLeft="14dp"
android:src="@drawable/fh" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="14dp"
android:layout_marginBottom="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="30dp"
android:background="@drawable/news"
android:orientation="vertical">
<TextView
android:id="@+id/news_info_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:gravity="center"
android:textSize="20sp" />
<ImageView
android:id="@+id/news_info_img"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_margin="14dp"
android:background="@color/blue"
android:scaleType="fitXY" />
<TextView
android:id="@+id/news_info_txv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="14dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.test1218.Const;
import com.example.test1218.R;
public class NewsInfo extends AppCompatActivity {
ImageView imageView;
TextView textView;
String qianzhui;
TextView title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_info);
qianzhui =getSharedPreferences("Myshujv", Context.MODE_PRIVATE)
.getString("qianzhui", "");
imageView=findViewById(R.id.news_info_img);
title=findViewById(R.id.news_info_title);
textView=findViewById(R.id.news_info_txv);
Glide.with(NewsInfo.this).load(qianzhui+ Const.newsBean.getCover()).into(imageView);
textView.setText(Html.fromHtml(Const.newsBean.getContent()));
title.setText(Const.newsBean.getTitle());
LinearLayout fh=findViewById(R.id.news_info_fh);
fh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NewsInfo.this.finish();
}
});
}
}
Service
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:background="@color/qianhui"
android:id="@+id/ser_rdg"
android:layout_width="100dp"
android:layout_height="match_parent">
<RadioButton
android:background="@drawable/back_bianse"
android:id="@+id/ser_f1"
android:textSize="18sp"
android:padding="8dp"
android:button="@null"
android:gravity="center"
android:text="生活服务"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:background="@color/huise"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<RadioButton
android:background="@drawable/back_bianse"
android:id="@+id/ser_f2"
android:textSize="18sp"
android:padding="8dp"
android:button="@null"
android:gravity="center"
android:text="便民服务"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:background="@color/huise"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<RadioButton
android:background="@drawable/back_bianse"
android:id="@+id/ser_f3"
android:textSize="18sp"
android:padding="8dp"
android:button="@null"
android:gravity="center"
android:text="车主服务"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RadioGroup>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ser_recy"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</LinearLayout>
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.RadioGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import park.Park;
import com.example.test1218.R;
import com.example.test1218.bus.SmartBus;
import sub.Subway;
import com.example.test1218.fengzhuang.MySerAdapter;
import com.example.test1218.fengzhuang.Okhehe;
import com.example.test1218.service.SerBean;
import com.example.test1218.service.SerData;
import com.example.test1218.waimaiFragment.waimai;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class SerFragment extends Fragment {
View view;
RecyclerView recy;
RadioGroup rdg;
Okhehe hehe;
String qianzhui;
List<SerBean> s1=new ArrayList<>(),s2=new ArrayList<>(),s3=new ArrayList<>();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view=inflater.inflate(R.layout.ser_fragment,container,false);
hehe = Okhehe.getInstance();
qianzhui = getActivity().getSharedPreferences("Myshujv", Context.MODE_PRIVATE)
.getString("qianzhui", "");
recy=view.findViewById(R.id.ser_recy);
rdg=view.findViewById(R.id.ser_rdg);
PutMySer();
return view;
}
private void PutMySer() {
String url=qianzhui+"/prod-api/api/service/list";
hehe.GetString(url, new Okhehe.FuncString() {
@Override
public void onResponse(String js) {
SerData sd=new Gson().fromJson(js,SerData.class);
s1.clear();
for (int i=0;i<sd.getRows().size();i++){
s1.add(sd.getRows().get(i));
}PutMyRdg();
s3.clear();
for (int s=0;s<s1.size();s++){
if (s1.get(s).getServiceType().equals("生活服务")){
s3.add(s1.get(s));
}
}PutMySerView(s3);
recy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View v0 = recy.getLayoutManager().findViewByPosition(0);
v0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), Subway.class));
}
});
recy.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
// Comparator<SerBean> comparator=new Comparator<SerBean>() {
// @Override
// public int compare(SerBean serBean, SerBean t1) {
// if (serBean.getId()!=t1.getId()){
// return t1.getId()-serBean.getId();
// }else {
// return t1.getId()-serBean.getId();
// }
// }
// };
// Collections.sort(s1,comparator);
// for (int i=0;i<9;i++){
// s2.add(s1.get(i));
// }
// SerBean sb=new SerBean();
// sb.setServiceName("更多");
// s2.add(sb);
// recy.setAdapter(new MySerAdapter(getActivity(),s2,qianzhui));
// GridLayoutManager gd=new GridLayoutManager(getActivity(),5);
// recy.setLayoutManager(gd);
// recy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
// @Override
// public void onGlobalLayout() {
// View v9=recy.getLayoutManager().findViewByPosition(9);
// ImageView imageView=v9.findViewById(R.id.ser_item_img);
// imageView.setBackgroundResource(R.drawable.yuan_lanse);
// recy.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// }
// });
}
});
}
private void PutMyRdg() {
rdg.check(R.id.ser_f1);
rdg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.ser_f1:
s2.clear();
for (int s=0;s<s1.size();s++){
if (s1.get(s).getServiceType().equals("生活服务")){
s2.add(s1.get(s));
}
}PutMySerView(s2);
recy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View v0 = recy.getLayoutManager().findViewByPosition(0);
v0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), Subway.class));
}
});
recy.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
break;
case R.id.ser_f2:
s2.clear();
for (int s=0;s<s1.size();s++){
if (s1.get(s).getServiceType().equals("便民服务")){
s2.add(s1.get(s));
}
}PutMySerView(s2);
recy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View v0 = recy.getLayoutManager().findViewByPosition(0);
v0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), SmartBus.class));
}
});
View v2 = recy.getLayoutManager().findViewByPosition(2);
v2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), waimai.class));
}
});
recy.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
break;
case R.id.ser_f3:
s2.clear();
for (int s=0;s<s1.size();s++){
if (s1.get(s).getServiceType().equals("车主服务")){
s2.add(s1.get(s));
}
}PutMySerView(s2);
recy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View v0 = recy.getLayoutManager().findViewByPosition(0);
v0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), Park.class));
}
});
recy.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
break;
}
}
});
}
private void PutMySerView(List<SerBean> serBeans) {
recy.setAdapter(new MySerAdapter(getActivity(),serBeans,qianzhui));
GridLayoutManager gd=new GridLayoutManager(getActivity(),3);
recy.setLayoutManager(gd);
}
}
<?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="vertical">
<ImageView
android:id="@+id/ser_item_img"
android:layout_margin="8dp"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_gravity="center" />
<TextView
android:id="@+id/ser_item_txv"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" />
</LinearLayout>
Me
<?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">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@color/blue" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<TextView
android:id="@+id/grxx"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="个人信息" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<TextView
android:id="@+id/ddlb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="订单列表" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<TextView
android:id="@+id/xgmm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="修改密码" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<TextView
android:id="@+id/yjfk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="意见反馈" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<Button
android:id="@+id/me_btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_margin="14dp"
android:background="@drawable/btn_lanse"
android:text="退出登录"
android:textColor="@color/white"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
package com.example.test1218.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.test1218.ChangePsw;
import com.example.test1218.Login;
import com.example.test1218.R;
import com.example.test1218.xinx.xinxi;
public class MeFragment extends Fragment {
View view;
TextView grxx,ddlb,xgmm,yjfk;
Button btn;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view=inflater.inflate(R.layout.me_fragment,container,false);
grxx=view.findViewById(R.id.grxx);
grxx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), xinxi.class));
}
});
btn=view.findViewById(R.id.me_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), Login.class));
getActivity().finish();
}
});
xgmm=view.findViewById(R.id.xgmm);
xgmm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), ChangePsw.class));
}
});
return view;
}
}
xgmm
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/blue"
android:gravity="center"
android:text="修改密码"
android:textColor="@color/white"
android:textSize="22sp" />
<LinearLayout
android:id="@+id/change_fh"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_centerVertical="true">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_marginLeft="14dp"
android:src="@drawable/fh" />
</LinearLayout>
</RelativeLayout>
<EditText
android:id="@+id/change_omm"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="14dp"
android:layout_marginRight="14dp"
android:background="@drawable/edit"
android:hint="请输入原密码"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:singleLine="true" />
<EditText
android:id="@+id/change_upsw"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="14dp"
android:layout_marginRight="14dp"
android:background="@drawable/edit"
android:hint="请输入密码"
android:inputType="textPassword"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:singleLine="true" />
<EditText
android:id="@+id/change_reupsw"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="14dp"
android:layout_marginRight="14dp"
android:background="@drawable/edit"
android:hint="请输入确认密码"
android:inputType="textPassword"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:singleLine="true" />
<Button
android:id="@+id/change_btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="14dp"
android:background="@drawable/btn_lanse"
android:text="立即修改"
android:textColor="@color/white"
android:textSize="19sp" />
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.example.test1218.fengzhuang.Okhehe;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class ChangePsw extends AppCompatActivity {
EditText e1, e2, e3;
Button btn;
Okhehe hehe;
String qianzhui;
String token;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.change_psw);
LinearLayout fh=findViewById(R.id.change_fh);
fh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ChangePsw.this.finish();
}
});
hehe = Okhehe.getInstance();
qianzhui = getSharedPreferences("Myshujv", Context.MODE_PRIVATE)
.getString("qianzhui", "");
token=getSharedPreferences("Myshujv", Context.MODE_PRIVATE)
.getString("token", "");
e1 = findViewById(R.id.change_omm);
e2 = findViewById(R.id.change_upsw);
e3 = findViewById(R.id.change_reupsw);
btn=findViewById(R.id.change_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String omm = e1.getText().toString();
String upsw = e2.getText().toString();
String reupsw = e3.getText().toString();
if (omm.isEmpty()) {
Toast.makeText(ChangePsw.this, "原密码不能为空", Toast.LENGTH_SHORT).show();
return;
} else if (upsw.isEmpty()) {
Toast.makeText(ChangePsw.this, "密码不能为空", Toast.LENGTH_SHORT).show();
return;
}else if (reupsw.isEmpty()){
Toast.makeText(ChangePsw.this, "确认密码不能为空", Toast.LENGTH_SHORT).show();
return;
}else if (!upsw.equals(reupsw)) {
Toast.makeText(ChangePsw.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show();
return;
}
String url=qianzhui+"/prod-api/api/common/user/resetPwd";
Map map = new HashMap();
map.put("oldPassword", omm);
map.put("newPassword", upsw);
hehe.PutJSONObejct(url, token, map, new Okhehe.FuncJSONObejct() {
@Override
public void onResponse(JSONObject jo) {
if (jo.optString("code").equals("200")) {
Toast.makeText(ChangePsw.this, "修改成功", Toast.LENGTH_SHORT).show();
ChangePsw.this.finish();
} else {
Toast.makeText(ChangePsw.this, jo.optString("msg"), Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}
grxx
<?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="40dp"
android:background="@color/blue"
android:gravity="center"
android:text="个人信息"
android:textColor="@color/white"
android:textSize="22sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="头 像:"
android:textSize="20sp" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:background="@color/blue" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="用户名:"
android:textSize="20sp" />
<TextView
android:id="@+id/xx_uname"
android:text="123"
android:textSize="18sp"
android:layout_alignParentRight="true"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="性 别:"
android:textSize="20sp" />
<RadioGroup
android:id="@+id/xx_rdg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<RadioButton
android:id="@+id/xx_nv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
android:textSize="18sp" />
<RadioButton
android:id="@+id/xx_nan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:textSize="18sp" />
</RadioGroup>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="手机号:"
android:textSize="20sp" />
<EditText
android:id="@+id/xx_tel"
android:text="123"
android:layout_alignParentRight="true"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/huise" />
<Button
android:id="@+id/xx_btn"
android:textSize="18sp"
android:text="确认修改"
android:layout_gravity="center"
android:textColor="@color/white"
android:layout_margin="14dp"
android:background="@drawable/btn_lanse"
android:layout_width="match_parent"
android:layout_height="40dp"/>
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.test1218.R;
import com.example.test1218.fengzhuang.Okhehe;
import com.google.gson.Gson;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class xinxi extends AppCompatActivity {
EditText xx_tel;
TextView xx_uname;
RadioGroup rdg;
Button btn;
Okhehe hehe;
String qianzhui;
String token;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xinxi);
hehe = Okhehe.getInstance();
qianzhui = getSharedPreferences("Myshujv", Context.MODE_PRIVATE)
.getString("qianzhui", "");
token=getSharedPreferences("Myshujv", Context.MODE_PRIVATE)
.getString("token", "");
xx_tel=findViewById(R.id.xx_tel);
xx_uname=findViewById(R.id.xx_uname);
btn=findViewById(R.id.xx_btn);
rdg=findViewById(R.id.xx_rdg);
PutMyXinXi();
ChangeMyXinxi();
}
private void ChangeMyXinxi() {
final String url=qianzhui+"/prod-api/api/common/user";
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String tel=xx_tel.getText().toString();
RadioButton rdb=findViewById(rdg.getCheckedRadioButtonId());
if(tel.isEmpty()){
Toast.makeText(xinxi.this,"手机号不能为空",Toast.LENGTH_SHORT).show();
return;
}else if(rdb==null){
Toast.makeText(xinxi.this,"请选择性别",Toast.LENGTH_SHORT).show();
return;
}
Map sex_map=new HashMap();
sex_map.put("男","0");
sex_map.put("女","1");
String sex= String.valueOf(sex_map.get(rdb.getText().toString()));
Map map = new HashMap();
map.put("phonenumber",tel);
map.put("sex",sex);
hehe.PutJSONObejct(url, token, map, new Okhehe.FuncJSONObejct() {
@Override
public void onResponse(JSONObject jo) {
if (jo.optString("code").equals("200")) {
Toast.makeText(xinxi.this, "修改成功", Toast.LENGTH_SHORT).show();
xinxi.this.finish();
} else {
Toast.makeText(xinxi.this, jo.optString("msg"), Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
private void PutMyXinXi() {
String url=qianzhui+"/prod-api/api/common/user/getInfo";
hehe.GetTokenString(url, token, new Okhehe.FuncString() {
@Override
public void onResponse(String js) {
XxData xx=new Gson().fromJson(js,XxData.class);
xx_uname.setText(xx.getUser().getUserName());
xx_tel.setText(xx.getUser().getPhonenumber());
String sex=xx.getUser().getSex();
if(sex.equals("0")){
rdg.check(R.id.xx_nan);
}else {
rdg.check(R.id.xx_nv);
}
}
});
}
}