How to make text clickable only where the text is in android?
In my android app, I create a linear layout horizontal, and put two text
views. The first text view should have layout weight of 1, so it tried to
maximize its width. Also the first text view too, is click able. How can I
get it so that only the text part of it is click-able? Currently, the full
width of the text view is click-able...
Thanks
final LinearLayout UserLayout = new LinearLayout(this);
UserLayout.setOrientation(LinearLayout.VERTICAL);
UserLayout.setPadding(20, 20, 20, 20);
LinearLayout.LayoutParams taskMargin = new
LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
UserLayout.setLayoutParams(taskMargin);
personobj.layout = UserLayout;
TextView name = new TextView(this);
name.setText(Html.fromHtml("<u>" + personobj.lastname + ", " +
personobj.firstname + "</u>"));
name.setTextAppearance(this, R.style.text_link);
name.setLayoutParams(new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,
1));
name.setClickable(true);
name.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (MyHTTPFunctions.isNetworkAvailable(context)) {
MyInterface.RegisterForClose(ActivityEditUsers.this);
AsyncGetProfileInfo GetProfileTask = new
AsyncGetProfileInfo(ActivityEditUsers.this, personobj.ID);
GetProfileTask.execute();
} else {
Toast.makeText(context,
context.getResources().getString(R.string.no_internet),
Toast.LENGTH_LONG).show();
}
}
});
final TextView num = new TextView(this);
num.setText(String.format("%d", index+1));
num.setPadding(10, 10, 10, 10);
num.setGravity(Gravity.CENTER);
num.setTextAppearance(this, R.style.title_numbering);
num.setBackgroundResource(R.drawable.bg_title_numbering);
LinearLayout OptionLL = new LinearLayout(this);
OptionLL.setOrientation(LinearLayout.HORIZONTAL);
OptionLL.addView(name);
OptionLL.addView(num);
UserLayout.addView(OptionLL);
No comments:
Post a Comment