我想要TableView的示例并实现基于按钮点击的页面导航,例如NExt和prev按钮。请在android中为我提供TableView / TableLayout分页的链接。我是一个更新鲜的所以请请给出有布局说明的链接,我可能听起来模糊,但我没有其他选择在这里问。
答案 0 :(得分:0)
答案 1 :(得分:0)
请在此处找到分页的完整示例
这是我的活动课
public class TestActivity extends AppCompatActivity {
RecyclerView recyclerView;
LinearLayoutManager layoutManager;
TestAdapter testAdapter;
List<TestM> testMS;
private boolean loading = true;
int pastVisiblesItems, visibleItemCount, totalItemCount;
int testLast = 0;
ProgressBar progressbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
setInit();
}
public void setInit() {
recyclerView = findViewById(R.id.recyclerView);
progressbar = findViewById(R.id.progressbar);
layoutManager = new LinearLayoutManager(TestActivity.this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
testMS = new ArrayList<>();
for (int i=0; i<12; i++){
testLast = i;
testMS.add(new TestM("alex"+i));
}
testAdapter = new TestAdapter(TestActivity.this, testMS, recyclerView);
recyclerView.setAdapter(testAdapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
progressbar = findViewById(R.id.progressbar);
if (dy > 0)
{
visibleItemCount = layoutManager.getChildCount();
totalItemCount = layoutManager.getItemCount();
pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
if (loading) {
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount-1) {
loading = false;
Log.v("...", "Last Item Wow !");
progressbar.setVisibility(View.VISIBLE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
loadNextDataFromApi();
}
}, 1000);
}
}
}
}
});
}
public void click(int position) {
TestAdapter.ViewHolder viewHolder = (TestAdapter.ViewHolder) recyclerView.findViewHolderForAdapterPosition(position);
viewHolder.text_color.setTextColor(Color.parseColor("#245251"));
}
public void loadNextDataFromApi() {
loading = true;
int j = testLast+1;
int k = j+5;
for (int i = j; i < k; i++){
testLast = i;
testMS.add(new TestM("alex"+i));
}
progressbar.setVisibility(View.GONE);
testAdapter.notifyDataSetChanged();
}
}
这是我针对Testactivity的xml
<?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="com.production.myextracode.recyclerview.TestActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/progressbar"/>
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@+id/cv_test"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:visibility="gone"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
这是适配器
package com.production.myextracode.recyclerview;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.production.myextracode.R;
import java.util.List;
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.ViewHolder> {
private TestActivity context;
private List<TestM> testMS;
private RecyclerView recyclerView;
public TestAdapter(TestActivity context, List<TestM> testMS, RecyclerView recyclerView) {
this.context = context;
this.testMS = testMS;
this.recyclerView = recyclerView;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_test,parent,false);
ViewHolder rcv = new ViewHolder(itemView);
return rcv;
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
TestM model = testMS.get(position);
holder.text_color.setText(model.getName());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context.click(position);
}
});
}
@Override
public int getItemCount() {
return testMS.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView text_color ;
CardView cv_test;
private ViewHolder(View itemView) {
super(itemView);
text_color = itemView.findViewById(R.id.tv_test);
cv_test = itemView.findViewById(R.id.cv_test);
}
}
}
适配器的项目xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<android.support.v7.widget.CardView
android:id="@+id/cv_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="10dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="false">
<TextView
android:id="@+id/tv_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Test"
android:textSize="16sp" />
</android.support.v7.widget.CardView>
</RelativeLayout>
这是模型课
package com.production.myextracode.recyclerview;
public class TestM {
String name;
public TestM(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
希望这会对您有所帮助。
答案 2 :(得分:-1)