Table Layout and Button click event

This is my xml table layout file:

ID  Car No  Timein      Timeout     Charge    Print

1   AA-123  9:00        12:00       1000      btnprint

2   BB-123  10:00       1:00        1000      btnprint

3   CC-123  10:00       1:00        1000      btnprint 

On a print button click I want to get the row data and send it role by role to another activity.

How to get the table row values and button click parameter?

Answers


If the TextViews(I think Car No, TimeIn etc are all TextViews, right?) and the print Button are wrapped by a TableRow then it's pretty simple to get the data:

    printBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            TableRow tr = (TableRow) v.getParent();
            TextView carNumber = (TextView) tr.findViewById(R.id.the_id_ofTheCarNumberTextView);
                            String carNumberText = carNumber.getText().toString();   
            TextView timeIn = (TextView) tr.findViewById(R.id.the_id_ofTheTimeInTextView);
                            String timeInText = carNumber.getText().toString();
            TextView timeOut = (TextView) tr.findViewById(R.id.the_id_ofTheTimeOutTextView);
                            String timeOutText = carNumber.getText().toString();
            // etc get the rest of the fields
            // put the data in the intent and start send it to the new
            // activity
        }
    });

Depending on the number of rows, you may want to look at the ListView widget.


Need Your Help

Javascript Regex match no spaces

javascript regex

I am trying to match the following string in Javascript Regex

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.