Select a tableRow within a TableLayout Dynamically

后端 未结 4 1624
轻奢々
轻奢々 2021-01-15 23:57

I\'m creating a Tablelayout with many TableRows dynamically, for example:

for(int i = 0; i

        
4条回答
  •  离开以前
    2021-01-16 00:33

    I found something cool and its working fine...

    TableLayout tl=(TableLayout)findViewById(R.id.maintable);
    
    ....
    
    TableRow tr1 = new TableRow(this);
    tr1.setLayoutParams(newLayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    
    
    
    TextView textview1 = new TextView(this);
    textview1.setText(etFirstname.getText());
    textview1.setPadding(5, 0, 0, 0);
    textview1.setTextColor(Color.YELLOW);
    textview1.setBackgroundColor(Color.GREEN);
    tr1.addView(textview1);
    
    TextView textview2 = new TextView(this);
    textview2.setText(etAge.getText());
    //textview2.setText(etAge.getText());
    textview2.setPadding(5, 0, 0, 0);
    textview2.setTextColor(Color.RED);
    textview2.setBackgroundColor(Color.GRAY);
    tr1.addView(textview2);
    
    
    
    tr1.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
            TableRow tr1=(TableRow)v;
            TextView tv1= (TextView)tr1.getChildAt(0);
    
            Toast.makeText(getApplicationContext(),tv1.getText().toString(),Toast.LENGTH_SHORT).show();
    
        }
    });
    
    
    tl.addView(tr1);
    

提交回复
热议问题