我有活动ListView
。我需要添加几个项目userWillGo
并添加OnClickListener
到它们。
这是一个简单的代码,它不起作用,因为我OnClickListeners
只有在活动开始时才能得到所有项目的反应。
public class UserDetailActivity extends Activity{
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.l_user_detail);
Intent intent = getIntent();
User user = (User) intent.getSerializableExtra("class");
...
userWillGo = (LinearLayout) findViewById(R.id.linerLayout_userDetail_willGoTO);
if (user.getUserWillGo().size() > 0)
for (int i = 0; i < user.getUserWillGo().size(); i++) {
View myView = (View) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_list, userWillGo, false);
...
myView.setOnClickListener(mOnClickListener(this, curentEvent));
userWillGo.addView(myView);
}
...
}
private View.OnClickListener mOnClickListener(UserDetailActivity userDetailActivity, Event curentEvent) {
Intent i = new Intent(userDetailActivity, EventDetailActivity.class);
i.putExtra("class", curentEvent);
startActivity(i);
return null;
}
帮助修复此错误。谢谢。