横向菜单和xlistview


//依赖 

compile 'com.astuetz:pagerslidingtabstrip:1.0.1' 


1.xlm


 <com.astuetz.PagerSlidingTabStrip
     android:id="@+id/pstp"
     android:layout_gravity="center"
     android:layout_width="match_parent"
     android:layout_height="40dp"></com.astuetz.PagerSlidingTabStrip>

<android.support.v4.view.ViewPager
    android:id="@+id/vip"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></android.support.v4.view.ViewPager>
 
2.MainActivty
  String[] title={"推荐","野史","后宫","解密"};
    private ViewPager vip;
    private PagerSlidingTabStrip pst;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//初始化id
        vip = (ViewPager) findViewById(R.id.vip);
        pst = (PagerSlidingTabStrip) findViewById(R.id.pstp);

        Adapter adapter = new Adapter(getSupportFragmentManager());
//如果要是在Fragment里面做的话,那么需要
getActivity().getSupportFragmentManager()
就行啦
 
//关联
        vip.setAdapter(adapter);
        pst.setViewPager(vip);
    }

//    适配器
    class Adapter extends FragmentPagerAdapter{

        public Adapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }

        @Override
        public Fragment getItem(int position) {

            Fragment fra=null;

            switch (position){
                case 0:
                    fra=new Fragment1();
                    break;
                case 1:
                    fra=new Fragment2();
                    break;
                case 2:
                    fra=new Fragment3();
                    break;
                case 3:
                    fra=new Fragment4();
                    break;
            }
            return fra;
        }

        @Override
        public int getCount() {
            return title.length;
        }
    }
}


3.fragmenty 以及里面的xlistview


//    网址
    String path="http://169.254.56.108:8080/aa.json";
    private XListView xlv;
    private List<Bean.ArrayBean> array;

    private MyAdapter myAdapter;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            myAdapter.notifyDataSetChanged();
            xlv.stopRefresh();
            xlv.stopLoadMore();
        }
    };
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

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

        xlv = (XListView) view.findViewById(R.id.xlv);


        indata();

        xlv.setPullRefreshEnable(true);
        xlv.setPullLoadEnable(true);
        xlv.setXListViewListener(this);

//        点击传值
        xlv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

                Intent intent=new Intent(getActivity(),MainActivity2.class);

                intent.putExtra("tyte",array.get(position-1).getTitle());
                intent.putExtra("ty",array.get(position-1).getContent());

                startActivity(intent);
                return false;
            }
        });

        return view;
    }

//    刷新
   @Override
    public void onRefresh() {

       handler.postDelayed(new Runnable() {
           @Override
           public void run() {

               array.add(0,array.get(4));
           }
       },2000);
        handler.sendEmptyMessage(0);

    }
//加载
    @Override
    public void onLoadMore() {

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                array.add(array.get(4));
            }
        },2000);
        handler.sendEmptyMessage(0);

    }

//    异步加载请求数据
    private void indata(){
        new AsyncTask<String,Void,String>(){
            private ByteArrayOutputStream outputStream;

            @Override
            protected String doInBackground(String... params) {

                try {
                    URL url = new URL(params[0]);

                    HttpURLConnection connection= (HttpURLConnection) url.openConnection();
                    connection.setRequestMethod("GET");
                    connection.setConnectTimeout(3000);
                    int responseCode = connection.getResponseCode();

                    if(responseCode==200){
                        InputStream inputStream = connection.getInputStream();

                        outputStream = new ByteArrayOutputStream();
                        int len;
                        byte[] by=new byte[1024];

                        while ((len=inputStream.read(by))!=-1){
                            outputStream.write(by,0,len);
                        }

                        outputStream.close();
                        inputStream.close();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
                return outputStream.toString();
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);

                Gson gson = new Gson();
                Bean fromJson = gson.fromJson(s, Bean.class);

                array = fromJson.getArray();

                myAdapter = new MyAdapter();
                xlv.setAdapter(myAdapter);
            }
        }.execute(path);
    }


//xlistview适配器
    class MyAdapter extends BaseAdapter{

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

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

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

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            convertView=View.inflate(getActivity(),R.layout.item,null);

            TextView text= (TextView) convertView.findViewById(R.id.text);
            TextView text2= (TextView) convertView.findViewById(R.id.text2);
            TextView text3= (TextView) convertView.findViewById(R.id.text3);

            text.setText(array.get(position).getTitle());
            text2.setText(array.get(position).getType());
            text3.setText(array.get(position).getNumber());
            

            return convertView;
        }
    }
}

4.fragment.xml


<com.bawei.util.XListView
    android:id="@+id/xlv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></com.bawei.util.XListView>
 
5.item.xml
 
<LinearLayout
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:textSize="20sp"
        android:text="场表U盾逼的那次哦啊"/>

    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:text="野史密文"/>
</LinearLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:orientation="vertical">

    <ImageView
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:layout_marginLeft="30dp"
        android:src="@mipmap/ic_launcher"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="18dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="点击数:"/>
        <TextView
            android:id="@+id/text3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:text="前"/>
    </LinearLayout>



</LinearLayout>
6.MainAcitvty2接受值
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    Intent intent = getIntent();

    String tyte = intent.getStringExtra("tyte");
   String ty = intent.getStringExtra("ty");
    TextView tv= (TextView) findViewById(R.id.tv);
    TextView ttv= (TextView) findViewById(R.id.ttv);

    tv.setText(tyte);

  ttv.setText(ty);


}
6.MainActvty的布局
<TextView
    android:id="@+id/tv"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:textSize="30sp"
    android:text="欢迎进入"/>

<TextView
    android:id="@+id/ttv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="数据"/>
 



ModernListView (Berlin, Tokyo [with fix], Rio) 很好的Delphi Firemonkey控件,可用作Android、iOS、MacOS、Windows开发,比Delphi自带的listview更好用、功能更强大! ListView1.SetColorItemSelected(TAlphaColorRec.Orangered); ListView1.SetColorItemFill(TAlphaColorRec.Whitesmoke); ListView1.SetColorItemFillAlt(TAlphaColorRec.Lightgrey); ListView1.SetColorBackground(TAlphaColorRec.Whitesmoke); ListView1.SetColorItemSeparator(TAlphaColorRec.Red); ListView1.SetColorText(TAlphaColorRec.Darkmagenta); ListView1.SetColorTextSelected(TAlphaColorRec.Blueviolet); ListView1.SetColorTextDetail(TAlphaColorRec.Darksalmon); ListView1.SetColorHeader(TAlphaColorRec.Crimson); ListView1.SetColorTextHeader(TAlphaColorRec.Whitesmoke); ListView1.SetColorTextHeaderShadow(TAlphaColorRec.grey); ListView1.SetColorPullRefresh(TAlphaColorRec.Lime); ListView1.SetColorPullRefreshIndicator(TAlphaColorRec.Limegreen); ListView1.SetColorStretchGlow(TAlphaColorRec.Limegreen); Style for ListView Columns Mode ListView1.ShowScrollBar - hide/show scrollbar ListView1.ItemsClearTrue - correct delete items ListView1.OffsetTop - indent of the first element ListView1.OffsetBottom - indent of the last element ListView1.getFirstVisibleItemIndex - first visible ItemIndex ListView1.getVisibleCount - amount of visible items ListView1.getLastVisibleItemindex - first visible ItemIndex + amount of visible items ListView1.SeparatorLeftOffset - indent for separator line ListView1.SeparatorRightOffset - indent for separator line ListView1.EnableTouchAnimation - enable/disable touch animation
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看READme.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值