package com.cardvalue.sys.fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader;
import com.cardvalue.sys.activity.LoadWebPage;
import com.cardvalue.sys.R;
import com.cardvalue.sys.adapter.MoreRecylerAdapter;
import com.cardvalue.sys.base.BaseFragment;
import com.cardvalue.sys.entity.MoreListDto;
import com.cardvalue.sys.newnetwork.Config;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
/**
* Recyler来取代listview 很多其它页面
* Created by cardvalue on 2016/4/5.
*/
public class MoreRecylerFragment extends BaseFragment {
String server = Config.getWeixinIp()+"";
private View view;
@Bind(R.id.recyclerView) RecyclerView recyclerView;
<span style="color:#cc0000;">@Bind(R.id.header) RecyclerViewHeader header;</span>
private List<MoreListDto> mMoreListDto= new ArrayList<>();
private MoreRecylerAdapter mMoreAdapter;
private int [] icons={R.mipmap.share,R.mipmap.pruoduce,R.mipmap.honor,
R.mipmap.contact,R.mipmap.about,R.mipmap.feedback,R.mipmap.service,R.mipmap.service};
private String[] title={"融资攻略","公司简单介绍","资质荣誉","联系方式","关于小企额","意见反馈","在线客服"};
private String[] activity={"","","","","com.cardvalue.sys.activity.AboutActivity",
"com.cardvalue.sys.activity.FeedBackActivity","com.cardvalue.sys.activity.CustomerServiceActivity"};
String url1=server+"new/m/more/question";
String url2=server+"/new/m/more/aboutUs?isApp=1";
String url3=server+"/new/m/more/honor?isApp=1";
String url4=server+"/new/m/more/contactUs?isApp=1";
private String[] url={url1,url2,url3,url4,"","",""};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view=inflater.inflate(R.layout.fragment_more_recyler,container,false);
ButterKnife.bind(this,view);
// 创建一个线性布局管理器
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(<span style="color:#cc0000;">LinearLayoutManager.VERTICAL</span>);<span style="color:#ff0000;">//设置垂直 还是水平</span>
// 设置布局管理器
recyclerView.setLayoutManager(layoutManager);
<span style="color:#990000;"> </span><span style="color:#cc0000;"> header.attachTo(recyclerView, true);//加入header</span>
view.findViewById(R.id.as).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
intent.addCategory("android.intent.category.DEFAULT");
//指定要拨打的电话号码
intent.setData(Uri.parse("tel:" + "4008-803-803"));
startActivity(intent);
}
});
for(int i=0;i<title.length;i++){
MoreListDto item=new MoreListDto();
item.setTitle(title[i]);
item.setIconIndex(icons[i]);
item.setActivity(activity[i]);
item.setUrl(url[i]);
if (i == 0 || i == 1) {
item.setShow(true);
}
mMoreListDto.add(item);
}
<span style="color:#cc0000;"> mMoreAdapter = new MoreRecylerAdapter(getActivity(),mMoreListDto);
recyclerView.setAdapter(mMoreAdapter);</span>
mMoreAdapter.setItemClickListener(new MoreRecylerAdapter.OnItemClickListener() {
@Override
public void onItemClick(View v, int position) {
// MoreListDto item=(MoreListDto)mListView.getItemAtPosition(position);
MoreListDto item =mMoreListDto.get(position);
if(!item.getActivity().equals("")){
try {
Intent intent = new Intent(getActivity(),Class.forName(item.getActivity().toString()));
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}else if(!item.getUrl().equals("")){
Intent intent = new Intent(getActivity(),LoadWebPage.class);
intent.putExtra("title", item.getTitle().toString());
intent.putExtra("url", item.getUrl().toString());
startActivity(intent);
}
}
});
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
setHeaderFields(0, R.string.more,0,0, 0,0);
super.onActivityCreated(savedInstanceState);
}
}
> <LinearLayout xmlns:andro xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/background_color" tools:context="com.cardvalue.sys.fragment.BasicFragment"> <include android:/> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.RecyclerView android: android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="horizontal" /> <com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader android: android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|top"> <LinearLayout android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content"> <RelativeLayout android: android:layout_width="match_parent" android:layout_height="90dp" android:background="@color/white" > <ImageView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="76dp" android:layout_marginTop="20dp" android:layout_centerVertical="true" android:src="@mipmap/service1" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@+id/imageView1" android:gravity="center_vertical" android:orientation="vertical" > <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="12dp" android:text="@string/phone" android:textColor="#010101" android:textSize="17sp" /> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="12dp" android:text="@string/time" android:textColor="#606060" android:textSize="12sp" /> </LinearLayout> </RelativeLayout> <View style="@style/lines_dbdbdb" /> </LinearLayout> </com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader> </FrameLayout> </LinearLayout>
compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.jakewharton:butterknife:7.0.1' compile 'com.bartoszlipinski.recyclerviewheader:library:1.2.0' 加入header compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1' compile 'com.squareup.retrofit2:retrofit:2.0.1' compile 'com.squareup.retrofit2:converter-gson:2.0.1' compile 'com.google.code.gson:gson:2.6.2' compile 'com.facebook.fresco:fresco:0.9.0+' compile 'io.reactivex:rxjava:1.1.2' compile 'io.reactivex:rxandroid:1.1.0' compile files('libs/fraudmetrix-2.0.5.jar') compile files('libs/locSDK_6.03.jar')