1
我是新來的在Android的Recycler視圖,我正在工作的樣式文本,所以我做了這樣的下面是我的適配器類。在Recycler視圖項目中應用字體後滾動滯後
public class MyAdapter extends RecyclerView.Adapter { private String[] mDataset; private ArrayList mContactData = new ArrayList(); Context context; // Provide a reference to the views for each data item // Complex data items may need more than one view per item, and // you provide access to all the views for a data item in a view holder public static class ViewHolder extends RecyclerView.ViewHolder { // each data item is just a string in this case public TextView mPhoneNumber; public TextView mContactName; public TextView mCallDuration; public TextView mCallType; private TextView mCallTime; public ViewHolder(View v) { super(v); mPhoneNumber = (TextView) v.findViewById(R.id.phone_number); mContactName = (TextView) v.findViewById(R.id.name_text); mCallDuration = (TextView) v.findViewById(R.id.call_duration_text); mCallType = (TextView) v.findViewById(R.id.call_type); mCallTime = (TextView) v.findViewById(R.id.date_time_text); } } // Provide a suitable constructor (depends on the kind of dataset) public MyAdapter(ArrayList mContactData,Context context) { this.mContactData = mContactData; this.context = context; } // Create new views (invoked by the layout manager) @Override public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // create a new view View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.new_layout, parent, false); // set the view's size, margins, paddings and layout parameters ViewHolder vh = new ViewHolder(v); return vh; } // Replace the contents of a view (invoked by the layout manager) @Override public void onBindViewHolder(ViewHolder holder, int position) { // - get element from your dataset at this position // - replace the contents of the view with that element Typeface typeface_rMedium = Typeface.createFromAsset(context.getAssets(), "Roboto-Medium.ttf"); Typeface typeface_rLignt = Typeface.createFromAsset(context.getAssets(), "Roboto-Light.ttf"); holder.mContactName.setText(mContactData.get(position).getContactName()); holder.mPhoneNumber.setText(mContactData.get(position).getContactNumber()); holder.mPhoneNumber.setTypeface(typeface_rMedium); holder.mCallDuration.setText(mContactData.get(position).getCallDuration()+" sec"); holder.mCallDuration.setTypeface(typeface_rLignt); holder.mCallTime.setText(Utility.getFromatedDateTime(Long.parseLong(mContactData.get(position).getCallTime()))); holder.mCallTime.setTypeface(typeface_rLignt); if(mContactData.get(position).getContactType().equalsIgnoreCase("STD")){ holder.mCallType.setText("S"); }else{ holder.mCallType.setText("L"); } } // Return the size of your dataset (invoked by the layout manager) @Override public int getItemCount() { return mContactData.size(); } }
之後滾動得到滯後,所以有人猜測出了什麼wrong.Thanks提前。
謝謝Akshay它的工作。 – leo