@Override public View getView(int position, View convertView, ViewGroup parent) { QuestionViewHolder viewHolder; QuestionModel model = this.items.get(position); if (convertView == null) { viewHolder = new QuestionViewHolder(); convertView = LayoutInflater.from(context).inflate(this.textViewId, null, false); viewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox); viewHolder.questionText = (TextView) convertView.findViewById(R.id.questionText); viewHolder.userInfo = (TextView) convertView.findViewById(R.id.userInfo); viewHolder.createdDate = (TextView) convertView.findViewById(R.id.dateCreated); viewHolder.checkBox.setTag(position); convertView.setTag(viewHolder); } else { viewHolder = (QuestionViewHolder) convertView.getTag(); viewHolder.checkBox.setTag(position); } viewHolder.questionText.setText(model.getQuestionText()); viewHolder.userInfo.setText( String.format(context.getResources().getString(R.string.created_by), model.getCreatedBy())); viewHolder.createdDate.setText( String.format(context.getResources().getString(R.string.create_at), model.getCreated())); viewHolder.checkBox.setChecked(sparseBooleanArray.get(position, false)); viewHolder.checkBox.setOnCheckedChangeListener(this); return convertView; }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.answer: pd.setMessage(getResources().getString(R.string.submitting_answer_text)); if (askedFrom.getTag() != null) { Location location = (Location) askedFrom.getTag(); lat = location.getLatitude(); lng = location.getLongitude(); } pd.show(); answerController.answerQuestion( mModel.getId(), answerText.getText().toString(), loginController.getUser(), lat, lng, answerCallback); return true; default: return false; } }