1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

Linear Layout HELP


Last Updated:

  1. ramesh_bh

    ramesh_bh Member This Topic's Starter

    Joined:
    Sep 16, 2010
    Messages:
    17
    Likes Received:
    1
    HI,

    My project requirement is like i have to display multiple rows, and each row should contain three columns name, email, address.
    If i click on any values i have to implement onclickListener also,
    Can anyone give example to do this type of requirements in LinearLayout or TableLayout.


    Here i am giving my input :
    Here is my code :
    LinearLayout lLayout1= null;
    LinearLayout main_lLayout= null;
    LinearLayout lLayout2= null;

    LinearLayout myLayout[] = new LinearLayout[2];
    @Override
    public void onCreate(Bundle icici) {
    super.onCreate(icici);

    main_lLayout = new LinearLayout(this);

    main_lLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT));
    main_lLayout.setOrientation(LinearLayout.VERTICAL);

    for(int i=0;i<2;i++) {
    TextView t1 = new TextView(this);
    t1.setText("Ramesh");
    t1.setPadding(0, 0, 20, 10);
    TextView t2 = new TextView(this);
    t2.setText("Kumar");
    t2.setPadding(0, 0, 20, 10);
    myLayout = new LinearLayout(this);
    myLayout.setOrientation(LinearLayout.HORIZONTAL);
    myLayout.addView(t1);
    myLayout.addView(t2);
    myLayout.setClickable(true);
    myLayout.setOnClickListener(this);
    main_lLayout.addView(myLayout);
    }

    setContentView(main_lLayout);
    }

    @Override
    public void onClick(View v) {
    for(int i=0;i<2;i++) {
    if(myLayout.isPressed()) {
    System.out.println("Count "+myLayout.getChildCount());
    System.out.println("Clicked."+((TextView)myLayout.getChildAt(0)).getText());
    }
    }
    }
    I got what row i am clicking , but
    For every row i have two columns, how to know what column i have clicked, Is this approach is correct ?
    Please help
     

    Advertisement

Share This Page

Loading...