Skip to content

Commit

Permalink
将动态添加的方式修改为另外一种,解决卡顿的麻烦
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellen2018 committed Jul 11, 2019
1 parent 35a3d20 commit ab34cd5
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 230 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".table2.Table2Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void bindTableItemViewHolder(MyItemViewHolder myItemViewHolder, int ro

@Override
public int getTableColumn() {
return 10;
return 5;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
superTableViewAdapter = new TableAdapter(getActivity(), xTitles, itemTitles);
superTableViewAdapter.setRowNumber(aa);
tableView.setTableViewAdapter(superTableViewAdapter);
view.findViewById(R.id.bt_remove).setOnClickListener(new View.OnClickListener() {
tableView.setOnVScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onClick(View v) {
superTableViewAdapter.notifyChanged();
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
Log.e("执行没?","ok");
if(scrollY+tableView.getHeight() >= (tableView.getRowNumber()-5)*tableView.getItemHeight()){
for(int i=0;i<10;i++) {
superTableViewAdapter.addRow();
}
}
}
});
initView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.GridLayout;
import android.widget.TextView;

import com.ellen.supertableview.R;
Expand Down Expand Up @@ -76,6 +77,12 @@ public void bindXYItemView(View view) {

}

@Override
public void bindAdapter() {
super.bindAdapter();
getTableView().getGridLayoutTable().setOrientation(GridLayout.VERTICAL);
}

static class XViewHolder extends XYItemViewHolder{
TextView textView;
public XViewHolder(View itemView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
btUpdate.setOnClickListener(this);
xList = new ArrayList<>();
yList = new ArrayList<>();
for (int i = 0; i < 1; i++) {
for (int i = 0; i < 2; i++) {
xList.add("x" + i);
}
for (int i = 0; i < 1; i++) {
for (int i = 0; i <2; i++) {
yList.add("y" + i);
}
railLineTableAdapter = new RailLineTableAdapter(this, xList, yList);
tableView.setTableViewAdapter(railLineTableAdapter);
tableView.setOnItemClickListener(new TableView.OnItemClickListener() {
@Override
public void onClickItem(View view, TableClick tableClick) {
Toast.makeText(Table2Activity.this,"点击了"+tableClick.getCloumn(),Toast.LENGTH_SHORT).show();
Toast.makeText(Table2Activity.this,"点击了("+tableClick.getRow()+","+tableClick.getCloumn()+")",Toast.LENGTH_SHORT).show();
}

@Override
Expand Down Expand Up @@ -74,17 +74,14 @@ private void toast(String content) {
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt1:
yList.add("3");
yList.add("5");
if(yList.size()>10){
xList.clear();
}
xList.add("3");
xList.add("5");
break;
case R.id.bt2:
yList.remove(0);
//xList.remove(0);
break;
case R.id.bt3:
yList.set(yList.size()-1,"5");
xList.set(yList.size()-1,"5");
break;
}
railLineTableAdapter.notifyChanged();
Expand Down
Loading

0 comments on commit ab34cd5

Please sign in to comment.