开发者

Deleting a particular view in a list of views

开发者 https://www.devze.com 2023-04-12 00:03 出处:网络
I am new to android.I am trying to add and remove views as in contacts application in android emulator. I am using layout inflator to continuously adding views .When I am deleting one of the view it g

I am new to android.I am trying to add and remove views as in contacts application in android emulator. I am using layout inflator to continuously adding views .When I am deleting one of the view it gets deleted from bac开发者_StackOverflow中文版kwards. The actual problem is I cannot find out the id for the exact button I'm clicking.

  public void plusButton(View v)
    {

    layout++;
    v=(View)findViewById(R.layout.newlayout);
    v = linflator.inflate(R.layout.newlayout, null); 
    rl1.addView(v);
    v.setId(layout); 

    if(layout==1)
    {
        Button office=(Button)findViewById(R.id.buttonType);
        System.out.println("button id found");
            office.setText("item 1");


    }
    else if(layout==2)
    {
        Button office=(Button)findViewById(R.id.buttonType);
        office.setText("item 2");

    }
    else if(layout==3)
    {
        Button office=(Button)findViewById(R.id.buttonType);
        office.setText("item 3");
    }
    else 
    {
        Button office=(Button)findViewById(R.id.buttonType);
        office.setText("item goes");
    }

 }

public void minusButton(View v)
{                                     
    v = (View)findViewById(layout);
    rl1.removeView(v);
    layout--;
}

Also the button text of first button only changes

help me..


use button.settag() and button.gettag()


Simply use getParent() to get the parent in the view group and remove that view

0

精彩评论

暂无评论...
验证码 换一张
取 消