Thanks Michali, I can provide you with a complete example. Pay particular attention to comments in onBindViewHolder ()
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewLedgerAdapter.ViewHolder>{ private final String TAG = RecyclerViewAdapter.class.getSimpleName(); private final float FINAL_OPACITY = 0.3f; private final float START_OPACITY = 1f; private final int ANIMATION_TIME = 500; private final int TYPE_ITEM = 0; private final int TYPE_DATE = 1; private final int TYPE_TRANSACTION = 2; private final int TYPE_PENDING = 3; private HashMap<Integer, Integer> mElementTypes; private List<Operation> mObjects; private Context mContext; private Utils.CURRENCIES mCurrencySelected;
Markup
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/operation_container_maximum" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="11dp" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="11dp" android:orientation="vertical"> <LinearLayout android:id="@+id/operation_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="14dp"> <ImageView android:id="@+id/ledgerOperationIcon" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/fondear" /> <ImageView android:id="@+id/ledgerAction" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:src="@drawable/operation_trade" /> </FrameLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical" android:weightSum="2"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:layout_weight="1" android:orientation="horizontal"> <TextView android:id="@+id/ledgerOperationDescription" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Descripcion" android:textColor="@color/ledger_desc" /> <TextView android:id="@+id/ledgerOperationCurrencyAmount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp" android:text="5000 BTC" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:layout_weight="1" android:orientation="horizontal"> <TextView android:id="@+id/ledgerOperationTimestamp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Fecha/Hora" android:textColor="@color/ledger_timestamp" /> <TextView android:id="@+id/ledgerOperationStatus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Status" /> </LinearLayout> </LinearLayout> </LinearLayout> <LinearLayout android:id="@+id/details_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="Something hidden" /> <ImageView android:layout_marginTop="15dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/user_btc" android:layout_gravity="center_horizontal"/> </LinearLayout> </LinearLayout>
Fragment
// This is one of the fragments used in the RecyclerViewAdapterCode, and also makes a HTTPRequest to fill the // view dynamically, you could laso use any of your fragments. public class FragmentCard extends Fragment { TextView mTextView; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_card, container, false); mTextView = (TextView) view.findViewById(R.id.tv_fragment_two); new UserActivityAsyncTask().execute(); return view; } private UserActivityOperation[] asyncMethodGetPendingWithdrawals(){ BitsoWithdrawal[] userWithdrawals = HttpHandler.getUserWithdrawals(getActivity()); int totalWithDrawals = userWithdrawals.length; UserActivityOperation[] appUserActivities = new UserActivityOperation[totalWithDrawals]; for(int i=0; i<totalWithDrawals; i++){ appUserActivities[i] = new UserActivityOperation(userWithdrawals[i], getActivity()); } return appUserActivities; } private class UserActivityAsyncTask extends AsyncTask<String, Void, Integer> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Integer doInBackground(String... strings) { // Precess Compound balance UserActivityOperation[] compoundBalanceProcessed = asyncMethodGetPendingWithdrawals(); return compoundBalanceProcessed.length; } @Override protected void onPostExecute(Integer result) { super.onPostExecute(result); mTextView.setText(result.toString()); } } }
source share