Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get text of the textview in the dynamically generated table?

i have written something like this....

TableRow  tr1;  
    TableRow  tr2;  
    TextView txt9;
    ...
    TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout);
    Display display = getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth();

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, LayoutParams.FILL_PARENT);

    for (int i = 0; i < strarr.length-1; i++)
    {
    strinarr = fun1.split(strarr[i].trim(),"^");
    tr1 = (TableRow) new TableRow(this);
    txt1=new TextView(this);
    txt9.setText(strinarr[0]);
    txt9.setBackgroundColor(intblue);
    txt9.setTextColor(intwhite);
    txt9.setClickable(true);
    txt9.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
    {
        Log.i("pagename",strpagename);
        String currenttext = txt9.getText().toString());
    }
    }
    });
    tr1.addView(txt9);
    tl.addView(tr1,new TableLayout.LayoutParams(layoutParams));
    }

i am able to get text on click but the stupid thing is that i am getting text of last textview in the table on all the textview click event... if somebody could tell me how to catch textview's text on focus or touch it would be really help full...

like image 238
Sourabh Avatar asked Nov 28 '25 09:11

Sourabh


1 Answers

change String currenttext = txt9.getText().toString()); to String currenttext = ((TextView)v).getText().toString());

like image 68
pankajagarwal Avatar answered Nov 29 '25 21:11

pankajagarwal