尝试使用public class TrainAdapter extends RecyclerView.Adapter<TrainAdapter.CustomViewHolder> {
private Context mContext;
private ArrayList<Train> mTrains;
public TrainAdapter(Context context, ArrayList<Train> trains) {
mContext = context;
mTrains = trains;
}
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int index) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.train_item, null);
CustomViewHolder viewHolder = new CustomViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(CustomViewHolder viewHolder, int position) {
Train currentTrain = mTrains.get(position);
viewHolder.platformText.setText(currentTrain.GetPlatform());
viewHolder.arrivalTimeText.setText(currentTrain.GetArrivalTime());
viewHolder.statusText.setText(currentTrain.GetStatus());
viewHolder.destinationText.setText(currentTrain.GetDestination());
viewHolder.destinationTimeText.setText(currentTrain.GetDestinationTime());
}
@Override
public int getItemCount() {
return (mTrains != null ? mTrains.size() : 0);
}
class CustomViewHolder extends RecyclerView.ViewHolder {
TextView platformText;
TextView arrivalTimeText;
TextView statusText;
TextView destinationText;
TextView destinationTimeText;
public CustomViewHolder(View itemView) {
super(itemView);
platformText =
(TextView)itemView.findViewById(R.id.train_item_platform_text);
arrivalTimeText =
(TextView)itemView.findViewById(R.id.train_item_arrival_time_text);
statusText =
(TextView)itemView.findViewById(R.id.train_item_status_text);
destinationText =
(TextView)itemView.findViewById(R.id.train_item_destination_text);
destinationTimeText =
(TextView)itemView.findViewById(R.id.train_item_destination_time_text);
}
}
}
并且Python告诉我找不到它,所以我尝试使用paramiko
进行安装并得到这个可怕的错误:http://pastebin.com/GFpgXB07
在OS X上。谢谢!
答案 0 :(得分:1)
OSX中的系统Python被操作系统用于各种任务,因此修改其包通常是一个非常糟糕的主意。此错误看起来像操作系统阻止您做一些可能非常有害的事情 - 通常,在您的系统中执行sudo pip install
任何 Python是个坏主意,除非您知道完全< / em>你正在做什么。
那么如何安全地安装和使用新包?使用virtualenvs。这使您可以创建一组独立的Python包,您可以根据需要进行修改和更新,而不会有损坏操作系统的风险。
答案 1 :(得分:1)
您似乎有权限问题。我同意jakevdp,但在那种情况下,virtualenv是你的解决方案。尝试使用--user选项进行安装。 Doc说(https://pip.pypa.io/en/stable/reference/pip_install/):
--user
Install to the Python user install directory for your platform. Typically ~/.local/.
此外,如果你养成这种习惯,你就可以安全地不用sudo搞砸你的系统。