1
ここには、ListView
という行のウィジェットはほとんどありません。Android:ListViewの行にある特定のウィジェットに、クリック可能なスパンをクリックすると表示されます
私はウィジェットの正しい位置を取得し、アダプター内の視認性を管理する必要があります。現在のところ、ListView
のlast item
に表示されています。
ここでもgetTag()
とsetTag()
を使用していますが、成功していません。この問題については
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.clist_item, null);
holder = new ViewHolder();
holder.requestion_layout = (RelativeLayout) convertView.findViewById(R.id.requestion_layout);
holder.submitAnswerBtn = (RelativeLayout) convertView.findViewById(R.id.submit_answer_btn);
holder.questionTitle = (TextView) convertView.findViewById(R.id.question_title);
//these are the widgets
holder.requestion_layout.setTag(position);
holder.submitAnswerBtn.setTag(position);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//trying to change visibility on click of Clickable Span
Spannable main_words = new SpannableString(items.get(position).getAnswer() + "");
int color1 = ContextCompat.getColor(activity, R.color.light_black);
main_words.setSpan(new ForegroundColorSpan(color1), 0, main_words.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int color2 = ContextCompat.getColor(activity, R.color.tab_green);
Spannable wordTwo = new SpannableString("Reply");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
//Toast.makeText(DummyActivity.this, "Click", Toast.LENGTH_LONG).show();
Integer position_clicked = (Integer) v.getTag();
//Widgets are not getting their positions here
holder.requestion_layout.setVisibility(View.VISIBLE);
holder.submitAnswerBtn.setVisibility(View.VISIBLE);
}
};
wordTwo.setSpan(clickableSpan, 0, wordTwo.toString().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
wordTwo.setSpan(new ForegroundColorSpan(color2), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordTwo.setSpan(new StyleSpan(Typeface.ITALIC), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
CharSequence concat = TextUtils.concat(main_words, " ", wordTwo);
holder.answerValue.setText(concat);
holder.answerValue.setMovementMethod(LinkMovementMethod.getInstance());
holder.answerValue.setHighlightColor(Color.TRANSPARENT);
holder.answerValue.setVisibility(View.VISIBLE);
holder.answerTitle.setVisibility(View.VISIBLE);
return convertView;
}