0
package com.example.assignmentone;

import java.util.ArrayList;

import android.R.integer;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.text.InputType;

import android.text.method.DigitsKeyListener;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.AlphabetIndexer;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TableLayout;

import android.widget.TableRow;

import android.widget.TableRow.LayoutParams;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends Activity {


EditText et;
static TableLayout tl;
Intent intent;
Button btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    et=(EditText) findViewById(R.id.et);
    //et2=(EditText) findViewById(R.id.et2);
    tl=(TableLayout) findViewById(R.id.tl);
    btn2=(Button) findViewById(R.id.btn2);


}
public void get(View v)
{
    startActivity(intent);

}

public void doo(View v)
{
    if(et.getText().toString().isEmpty()||Integer.parseInt(et.getText().toString())==0)

    {
        Toast.makeText(this, "Please Enter Valid Row #", Toast.LENGTH_SHORT).show();

        //Toast.makeText(this, et2.getInputType()+"", Toast.LENGTH_SHORT).show();

    }else {
        btn2.setEnabled(true);

        power(Integer.parseInt(et.getText().toString()));


    }
}
public void power(int r){
    //r=Integer.parseInt(et.getText().toString());
    //ArrayList<View>[][] table1 = new ArrayList[r][4];
    tl.removeAllViews();
    for(int i=0;i<=r;i++)
    {
        TableRow tRow=new TableRow(this);
        tRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        for(int j=0;j<4;j++)
        {
            if(i==0)
            {
                TextView tv=new TextView(this);
                tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

                if(j==0)
                {
                    tv.setKeyListener(DigitsKeyListener.getInstance(" abcdef:-.")); 

                    tv.setText("Name");
                    tRow.addView(tv);
                }

                else if(j==1)
                {
                    tv.setText("Subject 1");
                    tRow.addView(tv);
                }
                else if(j==2)
                {
                    tv.setText("Subject 2");
                    tRow.addView(tv);
                }
                else if( j==3)
                {
                    tv.setText("Subjct 3");
                    tRow.addView(tv);

                }

            }
            else if(i>0)
            {
                EditText temp=new EditText(this);
                temp.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                if(j==0)
                    {

                        temp.setInputType(1);
                        tRow.addView(temp);



                    }else if(j==1)
                    {
                        temp.setInputType(4098);
                        tRow.addView(temp);

                    }
                    else if(j==2)
                    {
                        temp.setInputType(4098);
                        tRow.addView(temp);

                    }
                    else if( j==3)
                    {
                        temp.setInputType(4098);
                        tRow.addView(temp);

                    }                   
            }


        }
        tl.addView(tRow);
    }


}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

SSH
  • 1,553
  • 1
  • 21
  • 39
  • what data do you want to pass? – varunkr Oct 03 '15 at 20:42
  • data thats wll enter in this table this code made a table with entries of name and number and i will pass this data in 2nd activty kindly tell how i did this – user3653748 Oct 03 '15 at 20:47
  • Intent.put() ...you can put data in these methos..chekout its overloaded forms – SSH Oct 03 '15 at 20:52
  • 2
    this is a trivial problem, have a look at this answer http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android – varunkr Oct 03 '15 at 20:54
  • Try this link http://stackoverflow.com/questions/4967740/transfer-data-from-one-activity-to-another-activity-using-intents – Vikas Chandra Oct 03 '15 at 20:55

1 Answers1

0

You can use putExtra and getExtra to send and receive data from activity to another. With this method you can send strings Serializable objects ... etc. see this example for sending Strings and this example for sending Objects

Community
  • 1
  • 1
abozaid
  • 827
  • 7
  • 11