private View CreateACard(MenuCard currCard) { CardView card = new CardView(this); View child = this.getLayoutInflater().inflate(R.layout.custom_card, null); ((ImageView) child.findViewById(R.id.crd_imag)).setBackgroundResource(currCard.imgRes); ((TextView) (child.findViewById(R.id.crd_txt))) .setText( currCard.name + Character.LINE_SEPARATOR + currCard.type + Character.LINE_SEPARATOR + "" + Character.LINE_SEPARATOR + currCard.desc); card.addView(child); return card; }
private void setup() { cardView = new CardView(context); cardView.setCardElevation(4f); cardView.setRadius(8f); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); tempTextView = new TextView(context); tempTextView.setText(benchmarkList.getName()); tempTextView.setTextAppearance(context, android.R.style.TextAppearance_Material_Display1); linearLayout.addView(tempTextView); startButton = new Button(context); startButton.setText("Start"); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.width = LinearLayout.LayoutParams.MATCH_PARENT; startButton.setLayoutParams(params); startButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { benchmarkList.start(); } }); linearLayout.addView(startButton); stopButton = new Button(context); stopButton.setText("Stop"); LinearLayout.LayoutParams paramsStop = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); paramsStop.width = LinearLayout.LayoutParams.MATCH_PARENT; stopButton.setLayoutParams(paramsStop); stopButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { benchmarkList.stop(); } }); linearLayout.addView(stopButton); LinearLayout resultLinearLayout = new LinearLayout(context); resultLinearLayout.setOrientation(LinearLayout.VERTICAL); lastResultTextView = new TextView(context); lastResultTextView.setTextAppearance(context, android.R.style.TextAppearance_Material_Body1); resultLinearLayout.addView(lastResultTextView); lastTimeTextView = new TextView(context); lastTimeTextView.setTextAppearance(context, android.R.style.TextAppearance_Material_Body1); resultLinearLayout.addView(lastTimeTextView); linearLayout.addView(resultLinearLayout); int margin = Conversions.toPx(context, 16); linearLayout.setPadding(margin, margin, margin, margin); resultLinearLayout.setPadding(0, margin, 0, 0); cardView.addView(linearLayout); dateFormat = android.text.format.DateFormat.getDateFormat(context); timeFormat = android.text.format.DateFormat.getTimeFormat(context); cardView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(context, BenchmarkListResultsActivity.class); intent.putExtra( BenchmarkListResultsActivity.INTENT_BENCH_NAME, benchmarkList.getName()); context.startActivity(intent); } }); }