Select a tableRow within a TableLayout Dynamically

后端 未结 4 1627
轻奢々
轻奢々 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:52

     /************ if table row is dynamic then this method else method 2 is perfect************/
    //if we want to applay listener on dynamic tablerow then use this
    //sure that perfect 
     TablRowe tr = new TableRow(this);
    tr.setClickable(true);
    tr.setId(100);// if in loop then add 1 counter with 100 like (100+counter) at end count++ it
     tr.setOnClickListener(this);
     @Override
        public void onClick(View v) 
    {
            switch (v.getId())
             {
             case 100: 
                   Toast.makeText(getApplicationContext(), "100", Toast.LENGTH_SHORT).show();   
                 break;
    
             case 101:
                Toast.makeText(getApplicationContext(), "101", Toast.LENGTH_SHORT).show();  
                 break;
    }
    /************************** for simple like this ************************/
       TableRow row1 = (TableRow)findViewById(R.id.row1);
    row1.setonClickListener(this);
    public void onClick(View v)
    {
    switch (v.getId())
             {
             case R.id.row1: 
               // do work
                 break;
              }        
    }
    

提交回复
热议问题