0
动态算我已经创建添加和移除视图dynamically.Everything工作fine.In这种看法有加两个TextView的一个消息,另一个用于显示消息count.If我添加消息,计数将会增加,并且会在第一个textview上设置文本。如果我删除的观点,整个视图得到removed.And的话,我想改变textview.But的计数值该值不changed.`添加和删除整数安卓
buttonAdd.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.question_row, null);
final TextView count1 = (TextView)addView.findViewById(R.id.textout);
TextView textOut = (TextView)addView.findViewById(R.id.count1);
textOut.setText(textIn.getText().toString());
count++;
count1.setText(""+count);
textIn.setText("");
Log.d("count---",""+count);
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
count1.setText("");
((LinearLayout)addView.getParent()).removeView(addView);
count--;
Log.d("count---",""+count);
count1.setText(""+count);
}});
container.addView(addView);
}
});
在第一图象我有添加5视图。和计数值获得相应
增加在第二图像我已删除的第三个项目是第三个项目移除。计数仍然是1,2,4,5。但我需要计数值为1,2,3,4。更新这个的方法是什么?
没有变化,它仍然是@rhari –
我做了一些改变,你可以再试一次吗? – rhari
我试过,但没有工作 –