Inflate the table

I have a TableLayout in which I add rows dynamically, first empty, and I want to load the xml in that row when the user clicks on it.

I have assigned the OnClick method to the string, but I do not know how to load the xml when it enters the onclick method.

public void onClick(View v){
 // CODE TO LOAD THE XML

 Toast.makeText(getApplicationContext(), "This should appear", Toast.LENGTH_SHORT).show();
}

I tried using inflate, but it seems I am not using it properly, because the application crashes when I click on a line.

How can I make a string contain xml?

+1
source share
2 answers

First set the tag for all TableRow when you first add to TableLayout. since you loaded TableRow dynamically, I hope this happens due to bloat, as shown below.

TableRow inflateRow = (TableRow) View.inflate(Activity, R.layout.table_row, null);

//Main TableLayout

TableLayout tblAddLayout = (TableLayout) findViewById(R.id.tblAddLayout);


for (int i=0;i<10;i++){

    inflate = (TableRow) View.inflate(myActivity, R.layout.table_row, null);
    //set tag for each TableRow
    inflate.setTag(i);
    //add TableRows to TableLayout
    tblAddLayout.addView(inflate);
    //set click listener for all TableRows
    inflateRow.setOnClickListener(this);
}

public void onClick(View v){

    String strTag = v.getTag().toString();
// Find the corresponding TableRow from the Main TableLayout using the tag when you click.

    TableRow tempTableRow = (TableRow)tblAddLayout.findViewWithTag(strTag); 
    //then add your layout in this TableRow tempTableRow.
}

In the onClick method above, you can load the XML file using the tag.

+8

TextView TableRow , XML TextView.

0

All Articles