我有一个在简单视图中调用的线性布局,我希望它在点击时展开并更改为完全不同的布局,但我无法在点击时更改它,因为它是最终的
LayoutInflater inflater = LayoutInflater.from(this);
final LinearLayout linearView = (LinearLayout) inflater.inflate(R.layout.linear_layout, null);
linearView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Change linearview to R.layout.linear_layout2
}
});
答案 0 :(得分:0)
将linearView声明为它所使用的类的成员变量。
public class MyActivity extends Activity {
private LinearLayout mLinearLayout;
//...//
public void initLayout() {
LayoutInflater inflater = LayoutInflater.from(this);
mLinearLayout = (LinearLayout)inflater.inflate(R.layout.linear_layout, null);
mLinearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Change mLinearLayout to R.layout.linear_layout2
}
});
}
}