Basically, my question is similar to this one:IBM Watson Assistant in Flutter: How to show options?
There is only one answer, telling me to decode the response and show the options as clickable UI elements. I already know how to decode it, but how to make them clickable as a button? Like this:
Example
I am not familiar with RecyclerView enough, maybe some method could do it?
you can add onClickListener to views so if you are using textviews for showing options you can add click listener like this in your RecyclerView Adapter class
textViews.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//YOUR CODE
}
});
Related
I have a textView inside a recyclerview currently that looks like this:
The full text says: "This is the place where I would put the information about the food item. I want to truncate the line to only show 3 lines and then when I press on the caret, it will expand to the maximum amount of lines."
If I click on the caret (the little down arrow at the top), I want it to expand so that I can see all the lines.
In my recyclerview adapter, I have the following code:
if (holder instanceof InfoViewHolder) {
((InfoViewHolder) holder).more.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!expandedInfo) {
((InfoViewHolder) holder).info.setMaxLines(Integer.MAX_VALUE);
expandedInfo = true;
}
((InfoViewHolder) holder).info.setMaxLines(3);
notifyItemChanged(position);
}
});
}
I'm just manipulating the maxLines in the textView to try and expand the space it will take in the textView so that the view will adjust itself when I notifyItemChanged, however, this does not work and my information textview does not expand.
Can anyone tell me how I can get this to work properly?
Using this library was probably the easiest and the quickest way to solve this puzzle:
https://github.com/Manabu-GT/ExpandableTextView
Although, I would have like to have done it the old fashion way instead of importing a new library so if anyone else has any ideas on how to do this without a library, feel free to post your suggestions below.
The reason it didn't work because ((InfoViewHolder) holder).info.setMaxLines(3); is called no matter what.
So, inside the OnClickListener, it should be:
int maxLines = expandedInfo ? Integer.MAX_VALUE : 3;
((InfoViewHolder) holder).info.setMaxLines(maxLines);
notifyItemChanged(position);
Also, about the ExpandableTextView library, currently it doesn't work in RecyclerView. See my comments on the issue.
I want to know which column user pressed in one TableRow object. It is header of table and i want to set sorting of items by chosen column.
I am able to use onClick listener in this case.
Problem is simmilar to How to click an specific TableRow within a TableLayout
You can do it like:
set Tag to each tablerow as follow:
tablerow.setTag(pass object of item which you want to set on this tablerow)
Now, set Listener:
tablerow.setListener(listener);
Listener should be pass from fragment/activity to Adapter.
So, when you click on any row, you will be able to listen it in fragment as:
listener = new View.OnClickListener() {
#Override
public void onClick(View v) {
v.getTag(); here you will get object which you set above.
}
}
So, using the tag object, you can able to find which row it is.
i would suggest using different layout for showing the data. GridView would be a nice solution. GridView docs There you should have the correct event, you are looking for On item click listener
I need to be able to programmatically dismiss an item inside a RecyclerView without the user actually swiping (instead I want to dismiss the item when they tap a button in the card). A lot of libraries I've seen only seem to support actual swipes.
I've tried using an existing library and just simulate a MotionEvent by creating a swipe on my own programmatically, but this interferes with another horizontal-swipe listener, so I'm wondering how else this could be done, ideally for a RecyclerView but if anyone knows how to for a ListView instead I can try to adapt that.
I've looked at this library as well as others for inspiration but I can't figure out how to trigger the swipes programmatically instead.
Use a ListView or RecyclerView with custom adapter, and call notifyDataSetChanged after removing an item from the datalist:
private void removeListItem(View rowView, final int position) {
Animation anim = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
anim.setDuration(500);
rowView.startAnimation(anim);
new Handler().postDelayed(new Runnable() {
public void run() {
values.remove(position); //Remove the current content from the array
adapter.notifyDataSetChanged(); //Refresh list
}
}, anim.getDuration());
}
Use one of the libraries that offer the swipe to dissmis funcionality ad extract the animation part, if im not mistaken its at the action_up at the onTouch(). Then call it from your onClick of the button.
I want to create a book in android. It's text come from database and every section of this text has a reference.I need to put clickable image inside text to show reference and when I click on image something like Toast which contain reference list will appear.
I didn't see something like that in typical app. any body have any suggestion to implement it ?
If I understand the question correctly, you will have a clickable image inside the activity. Next add a onClickListener to the image, inside of this display the toast with the reference.
ImageView img = (ImageView) findViewById(R.id.img);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(this, "https://www.google.com/", Toast.LENGTH_SHORT).show();
});
}
If you have multiple clickable images then you might be better off implementing the interface View.OnClickListener and adding the onClick method.
I think the best way is to use Linkify class provided by Android Framework - see http://developer.android.com/reference/android/text/util/Linkify.html for details.
Also you can play with google sample - https://github.com/googlesamples/android-TextLinkify
I'm kind of new to this whole thing so I need some help. I have an application that creates an ImageView OnCreate. I want to make this image clickable and have it open a browser to a specific link.
How would I do this? I'm having trouble specifically with the setOnClickListener because the parameters are not accepting an OnClickListener.
I'm developing for Android 1.6
You shoud set ImageView property clickable to true. Then set listener:
mImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// do stuff
}
});
You can subclass ImageView, if you like. Then you can override onClick in your own class. Rabas' method is probably more common though, and seen throughout Google's examples.