pulltorefreshscrollview 布局 主页面 MyListView主页面
2018-01-17 13:37
477 查看
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="zhanghaijiao.bawei.com.pulltorefreshscrollview_demo.MainActivity">
<!--scrollview:纵向滚动条 viewGroup
只能有一个子孩子
-->
<com.handmark.pulltorefresh.library.PullToRefreshScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scc">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!---viewpager-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round"/>
<!---listview列表 高度无法正确计算,只能显示一条数据
解决办法:自定义的listview -->
<zhanghaijiao.bawei.com.pulltorefreshscrollview_demo.MyListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv"></zhanghaijiao.bawei.com.pulltorefreshscrollview_demo.MyListView>
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</RelativeLayout>
package zhanghaijiao.bawei.com.pulltorefreshscrollview_demo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private PullToRefreshScrollView scrollView;
private int pageIndex=1;
private String url="https://api.tianapi.com/wxnew/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10&page="+pageIndex;
private MyAdapter adapter;
private List<Result.NewslistEntity> newslist=new ArrayList<>();
private int operType=1;//1:刷新 2:加载更多
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scrollView = findViewById(R.id.scc);
listView = findViewById(R.id.lv);
initScc();
requestNetData();
}
private void requestNetData() {
if(NetStateUtil.isConn(this)){
MyTask myTask=new MyTask(new MyTask.Icallbacks() {
@Override
public void updateUiByjson(String jsonstr) {
Toast.makeText(MainActivity.this,"111",Toast.LENGTH_SHORT).show();
Gson gson=new Gson();
Result result = gson.fromJson(jsonstr, Result.class);
if(operType==1){
newslist.clear();
}
//添加新的集合数据
newslist.addAll(result.getNewslist());
//设置适配器
setLvAdapter();
//关闭头尾视图
scrollView.onRefreshComplete();
}
});
myTask.execute(url);
}else{
NetStateUtil.showNoNetWorkDlg(this);
}
}
public void setLvAdapter(){
if(adapter==null){
adapter=new MyAdapter(this,newslist);
listView.setAdapter(adapter);
}else {
adapter.notifyDataSetChanged();
}
}
private void initScc() {
scrollView.setMode(PullToRefreshBase.Mode.BOTH);
scrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
//下拉刷新
ope
4000
rType=1;
pageIndex=1;
url="https://api.tianapi.com/wxnew/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10&page="+pageIndex;
requestNetData();
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
//上拉加载
operType=2;
pageIndex++;
url="https://api.tianapi.com/wxnew/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10&page="+pageIndex;
requestNetData();
}
});
}
}
package zhanghaijiao.bawei.com.pulltorefreshscrollview_demo;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
/**
* Created by jane on 2018/1/10.
*/
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//重新计算高度
int newHeight=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, newHeight);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="zhanghaijiao.bawei.com.pulltorefreshscrollview_demo.MainActivity">
<!--scrollview:纵向滚动条 viewGroup
只能有一个子孩子
-->
<com.handmark.pulltorefresh.library.PullToRefreshScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scc">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!---viewpager-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round"/>
<!---listview列表 高度无法正确计算,只能显示一条数据
解决办法:自定义的listview -->
<zhanghaijiao.bawei.com.pulltorefreshscrollview_demo.MyListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv"></zhanghaijiao.bawei.com.pulltorefreshscrollview_demo.MyListView>
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</RelativeLayout>
package zhanghaijiao.bawei.com.pulltorefreshscrollview_demo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private PullToRefreshScrollView scrollView;
private int pageIndex=1;
private String url="https://api.tianapi.com/wxnew/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10&page="+pageIndex;
private MyAdapter adapter;
private List<Result.NewslistEntity> newslist=new ArrayList<>();
private int operType=1;//1:刷新 2:加载更多
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scrollView = findViewById(R.id.scc);
listView = findViewById(R.id.lv);
initScc();
requestNetData();
}
private void requestNetData() {
if(NetStateUtil.isConn(this)){
MyTask myTask=new MyTask(new MyTask.Icallbacks() {
@Override
public void updateUiByjson(String jsonstr) {
Toast.makeText(MainActivity.this,"111",Toast.LENGTH_SHORT).show();
Gson gson=new Gson();
Result result = gson.fromJson(jsonstr, Result.class);
if(operType==1){
newslist.clear();
}
//添加新的集合数据
newslist.addAll(result.getNewslist());
//设置适配器
setLvAdapter();
//关闭头尾视图
scrollView.onRefreshComplete();
}
});
myTask.execute(url);
}else{
NetStateUtil.showNoNetWorkDlg(this);
}
}
public void setLvAdapter(){
if(adapter==null){
adapter=new MyAdapter(this,newslist);
listView.setAdapter(adapter);
}else {
adapter.notifyDataSetChanged();
}
}
private void initScc() {
scrollView.setMode(PullToRefreshBase.Mode.BOTH);
scrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
//下拉刷新
ope
4000
rType=1;
pageIndex=1;
url="https://api.tianapi.com/wxnew/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10&page="+pageIndex;
requestNetData();
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
//上拉加载
operType=2;
pageIndex++;
url="https://api.tianapi.com/wxnew/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10&page="+pageIndex;
requestNetData();
}
});
}
}
package zhanghaijiao.bawei.com.pulltorefreshscrollview_demo;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
/**
* Created by jane on 2018/1/10.
*/
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//重新计算高度
int newHeight=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, newHeight);
}
}
相关文章推荐
- PullToRefreshScrollView隐藏刷新布局(使刷新布局不显示)
- PullToRefreshScrollView 嵌套gridview或listView,顶部布局顶上去的问题处理
- PullToRefreshScrollView包含复杂组合控件时的页面定位问题
- 布局PullToRefreshScrollView
- 占位布局之fragment01的布局---PullToRefreshScrollView+viewpager+listview
- PullToRefreshScrollView+GridView,实现向下滑动中隐藏自定义Action布局
- PullToRefreshScrollView 嵌套 ViewPager 冲突导致界面不显示的问题
- PullToRefreshScrollView的使用
- PullToRefreshScrollView+Banner+banner.Listview
- PullToRefreshScrollView的使用
- Android scrollToTop实现点击回到顶部(兼容PullTorefreshScrollview)
- PullToRefreshScrollView + 多条目
- PullToRefreshScrollView+ViewPager+MyListView
- PullToRefreshScrollView的使用
- PullToRefreshScrollView
- android下拉刷新scrollview的用法pullToRefreshScrollview
- android PullToRefreshScrollView中 嵌套viewpage 解决不显示的问题
- ListView结合PullToRefreshScrollView 下拉刷新
- PullToRefreshScrollView的应用
- PullToRefreshScrollView的使用