gpt4 book ai didi

Android 在使用 JSON 数据填充表格布局时提高了性能

转载 作者:搜寻专家 更新时间:2023-11-01 08:52:45 31 4
gpt4 key购买 nike

有一个 WebService 在请求时返回 500 行 2darray 的 JSON 字符串。数组大小约为 45KB。填充数据所需的平均时间为 20 秒。

是这样的:

public View PopulateData(String json_data)
{
ja = new JSONToStringArray(json_data);
number_of_columns = ja.getColumns();
al = ja.getArrayList();

int column_num = 0;
int row_num = -1;
Activity activity = (Activity)main;

table.setId(CTlist.indexOf(CT));

initialState = new String[(al.size()/number_of_columns)][number_of_columns];

for (String item : al)
{
if (column_num % number_of_columns == 0)
{
row = new TableRow(main);
row.setGravity(Gravity.CLIP_HORIZONTAL);
row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
row.setClipChildren(true);
row.setId(10000 + row_num);
table.addView(row);
column_num = 0;
row_num++;
}




et = new EditText(main);
et.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
et.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
int px = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 150, activity.getResources().getDisplayMetrics());
et.setMaxWidth(px);
et.setText(item);
et.setId(column_num);
et.setBackgroundResource(R.drawable.rounded_rect);


initialState[row_num][column_num] = item;


et.setOnFocusChangeListener(new View.OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (!(v instanceof EditText))
{
return;
}
EditText tableEt = (EditText)v;

if(hasFocus)
{
tableEt.setTag(tableEt.getText().toString());
tableEt.setText("");
}
else
{
if(tableEt.getText().toString().equals(""))
{
tableEt.setText(tableEt.getTag().toString());
tableEt.setTag(null);
}

}
}
});

et.setOnEditorActionListener(new OnEditorActionListener() {

@Override
public boolean onEditorAction(TextView arg0, int arg1,
KeyEvent arg2) {
// TODO Auto-generated method stub
if (arg2.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
if(arg2.isAltPressed())
{
return true;
}
View v = arg0.focusSearch(View.FOCUS_DOWN);
if(!(v instanceof EditText))
{
KeyEvent.changeAction(arg2, KeyEvent.FLAG_CANCELED);
return true;
}
EditText etBelow = (EditText)v;
if (etBelow != null)
{
if (arg0.getText().toString().equals(""))
{

arg0.setText(arg0.getTag().toString());
arg0.setTag("");
}
etBelow.requestFocus();
}
KeyEvent.changeAction(arg2, KeyEvent.FLAG_CANCELED);
}
return true;
}


});

row.addView(et);
column_num++;

}


view = table;
return view;
}

任何东西都可以接受,即使是完全改变我做事的方式,只要它能快速填满我的 table 。

延迟主要是et.SetText(item);造成的其次是 row.AddView(et);

最佳答案

我会考虑使用:

关于Android 在使用 JSON 数据填充表格布局时提高了性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21623207/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com