我需要点击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);
}
答案 0 :(得分:0)
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);
}
试试这种方式