android – ExpandableListView Group button如何擷取getGroupView裡的參數groupPosition

來源:互聯網
上載者:User

ExpandableListView Group 裡放了一個button,但是button監聽器如何擷取getGroupView裡的參數groupPosition呢?如果在button的監聽器裡直接使用groupPosition,會報錯,因為groupPosition不是final類型、、糾結了許久,在getGroupView裡把參數改成final就行啦、原來我還以為不能改Override的方法,不改不知道、、、

需求:因為group是一條評論、而且裡面還有個評論的button(二級評論),點擊按鈕後,把評論更新到該評論的child裡面作為二級評論

// 擷取一級列表View對象@Overridepublic 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() {@Overridepublic 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() {@Overridepublic void onClick(DialogInterface dialog,int whichButton) {// User clicked OK so do some stuffCommentLevel2 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() {@Overridepublic void onClick(DialogInterface dialog,int whichButton) {// User clicked cancel so do some// stuffdialog.dismiss();}}).create().show();}});return layout;}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.