mainu
mainu

Reputation: 625

Cell click event in table layout..

I want to know how to get the cell click(ex:I want to click in the 3rd colomn of the 2nd row i.e. in 2x3 cell) event in a dynamic table view.I know about row click. But I want the particular cell click.. Is it possible in list view if list view contains rows along with colomns??

Please help

Thanks

Upvotes: 0

Views: 4673

Answers (2)

Nirali
Nirali

Reputation: 13805

Using TableLayout dynamically you can do this thing.

   TableLayout table = new TableLayout(getApplicationContext());
   TableLayout.LayoutParams tab_lp = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
   table.setLayoutParams(tab_lp);

  TableRow row = new TableRow(this);

  final TextView tvProduct = new TextView(getApplicationContext());

  LinearLayout.LayoutParams lp_l3 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, (LayoutParams.WRAP_CONTENT));
    tvProduct.setLayoutParams(lp_l3);
    tvProduct.setText(product);
    tvProduct.setClickable(true);   

    row.addView(tvProduct,  new TableRow.LayoutParams(1));
    table.addView(row, new TableLayout.LayoutParams());     

    tvProduct.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            Intent i = new Intent(Beers.this,BeerDetails.class);
            i.putExtra("Product_Name",tvProduct.getText().toString());
            startActivity(i);
         }
    });

    LinearLayout linearMain = (LinearLayout) findViewById(R.id.linearmainLayout);
    linearMain.addView(table);      
    linearMain.postInvalidate();

Upvotes: 1

Kevin Adesara
Kevin Adesara

Reputation: 3830

You can use GridView for this kind of UI instead of TableLayout or ListView. In GridView you can set OnItemClickListener. Read more about GridView here.

Upvotes: 0

Related Questions