android - ExpandableListView Group button如何获取getGroupView里的参数groupPosition

ExpandableListView Group 里放了一个button,但是button监听器如何获取getGroupView里的参数groupPosition呢?如果在button的监听器里直接使用groupPosition,会报错,因为groupPosition不是final类型、、纠结了许久,在getGroupView里把参数改成final就行啦、原来我还以为不能改Override的方法,不改不知道、、、

需求:因为group是一条评论、而且里面还有个评论的button(二级评论),点击按钮后,把评论更新到该评论的child里面作为二级评论

// 获取一级列表View对象
		@Override
		public View getGroupView(final int groupPosition, boolean isExpanded,
				View convertView, ViewGroup parent) {
			Log.v(TAG, "ExpandableList GroupView..");

			CommentLevel1 comment = mGroup.get(groupPosition);
			LayoutInflater layoutInflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			RelativeLayout layout = (RelativeLayout) layoutInflater.inflate(
					R.layout.list_item_comment1, null);

			ImageView headPic;
			Button reply;
			TextView nickName, commentContent, postTime, commentNum, commentItem;

			headPic = (ImageView) layout
					.findViewById(R.id.list_item_talkCommentLevel1_iv_headPic);
			reply = (Button) layout
					.findViewById(R.id.list_item_talkCommentLevel1_btn_reply);
			nickName = (TextView) layout
					.findViewById(R.id.list_item_talkCommentLevel1_tv_nickName);
			commentContent = (TextView) layout
					.findViewById(R.id.list_item_talkCommentLevel1_tv_comment);
			postTime = (TextView) layout
					.findViewById(R.id.list_item_talkCommentLevel1_tv_postTime);
			commentNum = (TextView) layout
					.findViewById(R.id.list_item_talkCommentLevel1_tv_commentNum);
			commentItem = (TextView) layout.findViewById(R.id.comment);

			User user = comment.getUser();

			if (null != user) {
				headPic.setImageBitmap(user.getHeadPicture());
				nickName.setText(user.getNickName());
			}
			commentContent.setText(comment.getContent());
			postTime.setText(comment.getPostTime().toLocaleString());
			if (comment.getCommentNum() != 0) {
				commentNum.setText(String.valueOf(comment.getCommentNum()));
			} else {
				commentNum.setVisibility(View.INVISIBLE);
				commentItem.setVisibility(View.INVISIBLE);
			}

			// If the button get the focus, the list won't expand any more.
			reply.setFocusable(false);
			reply.setClickable(true);
			reply.setTag(groupPosition);
			reply.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					LayoutInflater factory = LayoutInflater
							.from(TalkListCommentsActivity.this);
					final View replyView = factory.inflate(
							R.layout.list_item_reply, null);

					new AlertDialog.Builder(TalkListCommentsActivity.this)
							.setTitle(R.string.talk_postAComment)
							.setView(replyView)
							.setPositiveButton(R.string.positive,
									new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											// User clicked OK so do some stuff
											CommentLevel2 level2;
											User user;
											Bitmap headPic;
											BitmapDrawable bitmapDrawable = (BitmapDrawable) getResources()
													.getDrawable(
															R.drawable.myheadpic);
											headPic = bitmapDrawable
													.getBitmap();

											EditText commentText = (EditText) replyView
													.findViewById(R.id.talkList_et_reply);

											user = new User();
											level2 = new CommentLevel2();

											user.setNickName("用户 x");
											user.setHeadPicture(headPic);

											level2.setUser(user);
											String strComment = commentText
													.getText().toString();
											if (null != strComment) {
												level2.setContent(strComment);
											}
											level2.setPostTime(new Date());

											mChild.get(groupPosition).add(
													level2);
											mAdapter.notifyDataSetChanged();
										}
									})
							.setNegativeButton(R.string.cancel,
									new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											// User clicked cancel so do some
											// stuff
											dialog.dismiss();
										}
									}).create().show();
				}
			});

			return layout;
		}





  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值