【问题标题】:how to print the dynamically removed values from views in android如何从android中的视图中打印动态删除的值
【发布时间】:2014-07-16 10:37:56
【问题描述】:

我需要打印TextView 的文本,单击Button 将其删除。

这是我目前的代码:

public void function() {

    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View addView = layoutInflater.inflate(R.layout.row, null);

    TextView textOut = (TextView) addView.findViewById(R.id.textout);
    textOut.setText(test.get(i).toString());

    Button buttonRemove = (Button) addView.findViewById(R.id.remove);
    buttonRemove.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ((LinearLayout) addView.getParent()).removeView(addView);
            //need to print the value of the removed textview 
        }
    });

    container.addView(addView);
}

【问题讨论】:

  • 究竟是什么问题?

标签: android dynamic-programming layout-inflater


【解决方案1】:
public void function() {

LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);

TextView textOut = (TextView) addView.findViewById(R.id.textout);
textOut.setText(test.get(i).toString());
final String textToPrint = test.get(i).toString();
Button buttonRemove = (Button) addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Log.d("myLog",textToPrint );
        ((LinearLayout) addView.getParent()).removeView(addView);
        //need to print the value of the removed textview 
    }
});

container.addView(addView);

}

试试这个方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多