Code example for TableRow

Methods: setOnClickListeneraddView

0
      addFavorite(favoriteTable, index++, favorite);
    } 
  } 
   
  private void addFavorite(TableLayout favoriteTable, int index, final String favorite) {
    TableRow row = new TableRow(this);
     
    TextView indexView = new TextView(this);
    indexView.setTextSize(20);
    indexView.setText(index + ".");
    indexView.setPadding(10, 10, 10, 10);
    row.addView(indexView);
     
    TextView tv = new TextView(this);
    tv.setTextSize(20);
    tv.setMaxLines(2);
    tv.setMaxEms(10);
    tv.setEllipsize(TruncateAt.END);
    tv.setText(favorite);
    row.addView(tv);
     
    Button delete = new Button(this);
    delete.setPadding(10, 5, 10, 5);
    delete.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.ic_delete));
    row.addView(delete);
     
    favoriteTable.addView(row);
     
    row.setOnClickListener(new View.OnClickListener() {
      @Override 
      public void onClick(View v) {
        selectFavorite(favorite);
      } 
    }); 
Experience pair programming with AI  Get Codota for Java