prakash .k
prakash .k

Reputation: 635

clickale table llayout in android

In my application i have a table layout with 4 rows.In 1 row i displayed 2 data with some space in-between them which will look like having 2 columns.Now what i want is i have to start different intent by clicking this data.When i click 1st column it should start an intent and by clicking 2nd should start another intent.Is it possible to define region in table layout.Please help me.

Here is my table layout code:

<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical">    
<TableLayout 
        android:id="@+id/tablelayout"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:paddingRight="2dip"
        android:stretchColumns="0,1">

    <TableRow  >
 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Income">
     </TextView>      

        <TextView             
            android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Expense" android:layout_marginLeft="-150dp">
     </TextView>                     

    </TableRow>    
        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <View
                android:id="@+id/line1"
                android:layout_width="wrap_content"
                android:layout_height="1dip"
                android:layout_weight="1"
                android:background="#FF909090"
                android:padding="2dip" />
        </TableRow>


    <TableRow android:id="@+id/tablerowhouse"   android:layout_marginTop="30px">
 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Household:" >
     </TextView>            
        <TextView             
            android:id="@+id/text50" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Household:" android:layout_marginLeft="-250dp" >
     </TextView>   

          <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Household:" android:layout_marginLeft="-150dp" >
     </TextView>            
        <TextView             
            android:id="@+id/text53" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Household:" android:layout_marginLeft="-70dp" >
     </TextView>    

    </TableRow>



        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <View
                android:id="@+id/line1"
                android:layout_width="wrap_content"
                android:layout_height="1dip"
                android:layout_weight="1"
                android:background="#FF909090"
                android:padding="2dip" />
        </TableRow>


 <TableRow  android:layout_marginTop="40px">
 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Travel:" android:layout_span="3">
     </TextView>     
      <TextView
           android:id="@+id/text51"
           android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Travel" android:layout_marginLeft="-250dp">
     </TextView>     

           <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Travel:" android:layout_marginLeft="-150dp" >
     </TextView>            
        <TextView             
            android:id="@+id/text54" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Travel:" android:layout_marginLeft="-70dp">
     </TextView>    
 </TableRow>


     <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <View
                android:id="@+id/line1"
                android:layout_width="wrap_content"
                android:layout_height="1dip"
                android:layout_weight="1"
                android:background="#FF909090"
                android:padding="2dip" />
        </TableRow>


     <TableRow  android:layout_marginTop="40px">
 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Education:" android:layout_span="4">
     </TextView>     
      <TextView
           android:id="@+id/text52"
           android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Education" android:layout_marginLeft="-250dp">
     </TextView>  

           <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Education:" android:layout_marginLeft="-150dp" >
     </TextView>            
        <TextView             
            android:id="@+id/text55" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Education:"  android:layout_marginLeft="-70dp">
     </TextView>    
 </TableRow>


          <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <View
                android:id="@+id/line1"
                android:layout_width="wrap_content"
                android:layout_height="1dip"
                android:layout_weight="1"
                android:background="#FF909090"
                android:padding="2dip" />
        </TableRow>


          <TableRow  android:layout_marginTop="40px">
 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Total:" android:layout_span="5">
     </TextView>     
      <TextView
           android:id="@+id/totincome" 
           android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Total" android:layout_marginLeft="-250dp">
     </TextView>  

           <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Total:" android:layout_marginLeft="-150dp" >
     </TextView>            
        <TextView             
            android:id="@+id/totexpense" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Total:"  android:layout_marginLeft="-10dp">
     </TextView>    
 </TableRow>

               <TableRow  android:layout_marginTop="40px">
 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Balance:" android:layout_span="6"  android:layout_marginLeft="100dp" >
     </TextView>     
      <TextView
           android:id="@+id/balance"
           android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="balance" android:layout_marginLeft="-150dp" >
     </TextView>  


 </TableRow>



</TableLayout>
</LinearLayout>

Upvotes: 1

Views: 160

Answers (1)

Avi Kumar
Avi Kumar

Reputation: 4433

Simply add click event to individual text after initializing like

 Text1.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub


  Intent  i = new Intent(this, MainMenu.class);
        startActivity(i);
                }
            });

Upvotes: 2

Related Questions