【发布时间】:2015-08-11 09:48:16
【问题描述】:
我的代码运行良好。但问题是在我从网络服务收到数据之后。当我启动循环以创建多行时,我的活动会暂停 5 到 10 秒。可以从服务中接收的最大记录不超过 100。
我该如何解决这个问题?在不停止我的活动的情况下它应该生成多条记录。因为我已经有几条记录要迭代了。
LinearLayout parentLayout = (LinearLayout)findViewById(R.id.sheet);
LayoutInflater layoutInflater = getLayoutInflater();
View view;
JSONArray receivedData = (JSONArray) json.get("RESPONSE_DATA");
for(int i=0; i<receivedData.length(); i++){
view = layoutInflater.inflate(R.layout.row, parentLayout, false);
((TextView)view.findViewById(R.id.title1)).setText( (((JSONObject)receivedData.getJSONObject(i)).get("title1")).toString() );
((TextView)view.findViewById(R.id.title2)).setText( (((JSONObject)receivedData.getJSONObject(i)).get("title2")).toString() );
ToggleButton button = (ToggleButton)view.findViewById(R.id.button);
button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
View parentView = (View)buttonView.getParent();
if(isChecked){
parentView.setBackgroundColor(0x00000000);
}else{
parentView.setBackgroundColor(0xffDF9292);
}
}
});
parentLayout.addView(view);
}
【问题讨论】:
标签: android android-activity layout-inflater