删除视图列表中的特定视图

问题描述:

我是新来的android.I我试图添加和删除视图在android模拟器中的联系人应用程序。我正在使用布局充气器来连续添加视图。当我删除其中一个视图时,它会从后面删除。 实际的问题是我找不到我单击的确切按钮的ID。删除视图列表中的特定视图

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--; 
} 

而且第一个按钮的按钮上的文字只是改变

帮助我..

+0

在您的发布代码中,在第二行中您错了。 –

使用button.settag()button.gettag()

只需使用的getParent()获取父视图组中删除该视图