Android VIEWID你能用一个例子解释一下吗

Android VIEWID你能用一个例子解释一下吗 ,android,Android,VIEWID你能用一个例子解释一下吗 MyDBHandler dbHandler = new MyDBHandler(this); TableLayout tableLayout=(TableLayout)findViewById(R.id.table


VIEWID你能用一个例子解释一下吗
                                                                                                              MyDBHandler dbHandler = new MyDBHandler(this);
              TableLayout tableLayout=(TableLayout)findViewById(R.id.table);
              SQLiteDatabase db = dbHandler.getReadableDatabase();
                    // Start the transaction.
                   db.beginTransaction();
    String selectQuery = "SELECT date,description,amount FROM expdetails E `enter code here`WHERE E.date == date('now')";
         Cursor cursor = db.rawQuery(selectQuery, null);

        //lpw.setAdapter(adapter);


    if(cursor.getCount() >0)
    {
        while (cursor.moveToNext()) {
            // Read columns data
            _date = cursor.getString(cursor.getColumnIndex("date"));
            _desc = cursor.getString(cursor.getColumnIndex("description"));
            _amt = cursor.getString(cursor.getColumnIndex("amount"));

            // dara rows
            row = new TableRow(this);
            row.setLayoutParams(new   `enter code here` `enter code here`TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                    TableLayout.LayoutParams.MATCH_PARENT));

            String[] colText = {_date , _desc, _amt+""};
            //colText[0]=_date;
            //colText[1]=_desc;
            //colText[2]=_amt;
            for (String text : colText) {

                TextView tv = new TextView(this);
                tv.setLayoutParams(new `enter code here`TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT));
                tv.setGravity(Gravity.CENTER);
                tv.setTextSize(18);
                tv.setPadding(30, 10, 30, 10);
                tv.setText(text);
                row.setGravity(Gravity.CENTER);
                row.addView(tv);


               // row.setOnClickListener(rowOnClick);
                //row.getChildAt(0)
               /* row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        TextView tv1 =(TextView) row.getChildAt(0);
                        TextView tv2 = (TextView)row.getChildAt(1);
                         `enter code    here`Toast.makeText(getApplicationContext(),tv2.getText().toString(), `enter code here`Toast.LENGTH_LONG).show();
                        //showDialog(DIALOG_ID);


                    }
                });*/
            }
            tableLayout.addView(row);

    }

                }
   cursor.close();

    db.endTransaction();
}
 /*private View.OnClickListener rowOnClick = new       `enter code here`View.OnClickListener()   {
    public void onClick(View v) {
        //Highlight selected row
        `enter code here`       `enter code here`   `enter code here`//v.setBackgroundColor(getResources().getColor(android.R.color.holo_red_lig`enter code here`ht));
        final int k = v.getId();
        Toast.makeText(ExpenseDetails.this, colText[k],
                Toast.LENGTH_SHORT).show();
    }
};*/
@Override
public Dialog onCreateDialog(int id) {
    switch (id) {
        case DIALOG_ID:

        ArrayList<String> ops = new ArrayList<>();
        //lpw=new ListPopupWindow(this);
        ArrayAdapter adapter = new ArrayAdapter<String>(this, `enter code  here`        android.R.layout.simple_spinner_dropdown_item, ops);
        ops.add("Edit");
        ops.add("Delete");
        adapter.notifyDataSetChanged();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);


        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // The 'which' argument contains the index position
                // of the selected item
                TextView tv1 =(TextView) row.getChildAt(0);
                TextView tv2 = (TextView)row.getChildAt(1);

                switch (which) {
                    case 0:

                        Toast.makeText(getApplicationContext(), `enter code         here`tv1.getText().toString(), Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                        break;
                    case 1:
                        Toast.makeText(getApplicationContext(), `enter code       here`tv2.getText().toString(), Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                        break;

                }
            }
        });
        return builder.create();
    }
    return null;
}
While you create a table Row dynamically associate an Id with it and in onclick listener distinguish the row pressed with it's id

eg 
TableLayout tl=new TableLayout(context);
for(int i=0;i<20;i++){
TableRow tr = new TableRow(context);
tr.setId(i);
tr.setOnClickListener(this);
}

public void onClick(View view)
{

switch(view.getId())
{
case 1: 
doSomething();
break;
case 2: 
doSomething();
}

}

public void doSomething()
{

}


Similarly do it for a dialog