Select a tableRow within a TableLayout Dynamically

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

    change your code as for making TableRow Clickable set tr.setClickable(true) and add a setOnClickListener:

        private void createView(TableRow tr, TextView t, String viewdata) {
    
            t.SetText(viewdata, TextView.BufferType.Editable);
    
           //adjust the porperties of the textView
    
           //t.SetLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
    
            //You have to use Android.Graphics.Color not System.ConsoleColor;
            t.SetTextColor(Color.Blue);
            t.SetBackgroundColor(Color.Cyan); 
            t.SetPadding(5, 0, 0, 0);
    
            tr.SetPadding(0, 1, 0, 1); 
            tr.SetBackgroundColor(Color.Black); 
            tr.setClickable(true);
    
            tr.setOnClickListener(tablerowOnClickListener);//add OnClickListener Here
    
            tr.AddView(t); // add TextView to row.
    
    
       }
    private OnClickListener tablerowOnClickListener = new OnClickListener() {
            public void onClick(View v) {
                //GET TEXT HERE
                String currenttext = ((TextView)v).getText().toString());
            }
        };  
    

提交回复
热议问题