gpt4 book ai didi

java - ListView 加载速度更快

转载 作者:行者123 更新时间:2023-12-01 18:07:53 25 4
gpt4 key购买 nike

我正在使用 ListView,但它加载太慢,我需要它加载得更快,不知道如何让适配器一一加载每个 ListView ,这可能吗?这是我的代码:

                ArrayList<String> myTripOrigin = new ArrayList<>();
ArrayList<String> myTripDestiny = new ArrayList<>();
ArrayList<String> myTripHour = new ArrayList<>();
ArrayList <boolean[]> myTripSchedule = new ArrayList<>();
ArrayList<Boolean> myTripBools = new ArrayList<Boolean>();


for(int i = 0; i<response.body().size();i++)
{
myTripBools.add(response.body().get(i).isRol());
myTripOrigin.add(getAdress(new LatLng(Double.parseDouble(response.body().get(i).getOrigin_lat()),Double.parseDouble(response.body().get(i).getOrigin_lng()))));
myTripDestiny.add(getAdress(new LatLng(Double.parseDouble(response.body().get(i).getDestiny_lat()),Double.parseDouble(response.body().get(i).getDestiny_lng()))));
Date date = new Date((Long.parseLong(response.body().get(i).getArrival_time()))*1000L);
DateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss aa");
format.setTimeZone(TimeZone.getDefault());
String formatted = format.format(date);
myTripHour.add(formatted);


}

//Send the array to constructor
ListAdapter userAdapter = new CustomAdapterRoute(getApplicationContext(), myTripOrigin,myTripDestiny,myTripHour,myTripSchedule,myTripBools);
ListView userListView = (ListView) findViewById(R.id.listViewRoute);
userListView.setAdapter(userAdapter);

}

这是自定义适配器路线:

public class CustomAdapterRoute extends ArrayAdapter<String>{

private ArrayList<String> itemFrom = new ArrayList<>();
private ArrayList<String> itemTo = new ArrayList<>();
private ArrayList<String> itemHour = new ArrayList<>();
private ArrayList<boolean[]> itemSchedule = new ArrayList<>();
private ArrayList<Boolean> itemRole = new ArrayList<>();

//Send arrays
public CustomAdapterRoute(Context context, ArrayList<String> stringArray, ArrayList<String> stringTo, ArrayList<String> stringHour, ArrayList<boolean[]> stringSchedule,ArrayList<Boolean> boolRole){
super(context, R.layout.custom_row_route,stringArray);

//save the arrays in global var
this.itemFrom = stringArray;
this.itemTo = stringTo;
this.itemHour = stringHour;
this.itemSchedule = stringSchedule;
this.itemRole = boolRole;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

LayoutInflater customInflater = LayoutInflater.from(getContext());

final View customView = customInflater.inflate(R.layout.custom_row_route, parent, false);

String singleFrom = itemFrom.get(position);
String singleTo = itemTo.get(position);
String singleHour = itemHour.get(position);
boolean singleRole = itemRole.get(position);

//Get a string chain from the booleans routine from each user
//String singleSchedule = ScheduleText(itemSchedule.get(position));

//Get TextView from the custom row
TextView customText = (TextView) customView.findViewById(R.id.fromText);
TextView customTextTo = (TextView) customView.findViewById(R.id.toText);
TextView customTextHour = (TextView) customView.findViewById(R.id.hourText);
ImageView RoleImage = (ImageView) customView.findViewById(R.id.ImageRole);
//TextView customTextSchedule = (TextView) customView.findViewById(R.id.repeatText);

//set the image of the role
if(singleRole) {RoleImage.setImageResource(R.mipmap.steer3);}
else{ RoleImage.setImageResource(R.mipmap.hand3);}


//Give values from each position of the array
customText.setText(singleFrom);
customTextTo.setText(singleTo);
customTextHour.setText(singleHour);


//User want to edit a route
ImageButton buttonEditTrip = (ImageButton) customView.findViewById(R.id.ImageRole);

return customView;

}

}

最佳答案

跟我想的一样。您应该使用持有者模式:http://developer.android.com/training/improving-layouts/smooth-scrolling.html让它更快

关于java - ListView 加载速度更快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34882644/

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