I have some hash tags in a TextView
which are starts with \'#\'
Example:\"#one#two Hello World #three\".
I wants these hash tags clickable separ
You can use LinearLayout
:
In xml add :
Init layout :
// EditText to write Tags.
EditText tag = (EditText) findViewById(R.id.tag_ET));
// Button used to add tags
Button addTagBtn = (Button) findViewById(R.id.add_Btn));
// layout contains added tags.
final LinearLayout tagsView = (LinearLayout) findViewById(R.id.tags_view);
Add tags to tagView :
final String tagTxt = tagEt.getText().toString();
if (!tagTxt.isEmpty()) {
Spannable buttonLabel = new SpannableString(tagTxt);
// clear tag edit text
tagEt.setText("");
// add tag to layout
Button btn = new Button(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lout.addView(btn, tagsView);
btn.setText(buttonLabel);
btn.setBackgroundResource(R.drawable.hover);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Toast whatever you want.
Toast.makeText(getApplicationContext(), tagTxt,1000).show();
}
});
}