I have an arrayList of books. It contains the book name and book tags (say history, novel, story etc.). I have used RecyclerView for listing. It works fine but the problem is that here tags are showing like text in the box.
Sometimes tags are not showing at the initial loading. after scrolling tags get displayed.
I don't know whats happening in the code. I think the issue is with the RecyclerView. I am setting thet visibility to VISIBLE in onBindViewHolder still didnt get.
here is my xml
<LinearLayout
android:layout_width="220dp"
android:layout_height="wrap_content"
android:id="#+id/tag_layout"
android:layout_marginTop="2dp"
android:layout_alignLeft="#+id/story_name"
android:layout_below="#id/story_name">
<TextView
android:id="#+id/tag1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:textSize="12dp"
android:paddingLeft="6dp"
android:paddingRight="11dp"
android:paddingBottom="3.5dp"
android:background="#drawable/roundedcorner"/>
</LinearLayout>
onBindViewHolder
holder.tag1.setText("tag name ");
holder.tag1.setVisibility(View.VISIBLE);
Related
I am currently working on an app and my layout is as follows:
I have a recyclerview holding all of my items, each item has a textview above an imageview. So the text view can expand up to 3 lines but only if needed. The recyclerview is using a gridlayout manager to display all of my items.
The problem is that currently when the text view expands to have more than 1 line it presses down the image instead of keeping it aligned with the other images in the row
What I currently have
What I want is to prevent the text view from pressing down on the image but instead build it's way up so that way the images stay normal and the text view will grow upwards like the image below.
What I want
Is there any way to achieve this? I would think it shouldn't be hard but I can't seem to find a way to accomplish this, or more likely, can't google the right terms to find the solution I'm looking for.
So I found an answer, I had to set two properties for my textview:
android:lines="3"
android:gravity="bottom"
so in the end each item had a layout below:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingStart="31dp"
android:paddingEnd="32dp">
<TextView
android:id="#+id/app_name"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/app_card_temp_name"
android:textSize="#dimen/product_list_text_size"
android:fontFamily="sans-serif-condensed"
android:lines="3"
android:textAlignment="center"
android:textColor="#color/app_name_product_list_color"
android:typeface="normal"
android:gravity="bottom" />
<ImageView
android:id="#+id/app_thumbnail"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="#dimen/product_list_image_dimensions"
android:layout_below="#id/app_name"
android:paddingTop="#dimen/product_list_text_bottom_padding"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I have a textview which get text from server and that text is a full paragraph like and has a html format. Now i am using maxline=2 in xml to show some of the text in two lines. I have tried many tricks but nothing works. Here is my xml code, please tell me what going wrong with it?
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/subject"
android:layout_toLeftOf="#+id/date"
android:maxLines="2"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:textColor="#666666"
android:textAppearance="?android:attr/textAppearanceMedium" />
And this is how i set text into that textview.
message.setText(Html.fromHtml(details.Description()));
It always looks like this,
This is the text
that came from server
As you can notice above where the first line start from the second on not starting from there below. I want both to start from same position. The problem is text coming from server is a single sentence and i can't use "\n" or </br> like tags and also this text is in the listview setting by getview. And i have also tried android:gravity="center_horizontal" and android:layout_gravity="center_horizontal"
Please cope with me as im new to android and i have done a lot of searching on my own, about this, and im fed up not finding a proper way.
This is my custom listview template. rowbuttonlayout.xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="19.6dp" >
</TextView>
<CheckBox
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3.6dp"
android:layout_marginRight="9.6dp" >
</CheckBox>
<TextView
android:id="#+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/check"
android:layout_alignBottom="#+id/check"
android:layout_toLeftOf="#+id/check"
android:text="#string/nothing" />
</RelativeLayout>
What i want is to create something like this in this pic without the header and footer.
http://www.vogella.com/articles/AndroidListView/images/xinteractive10.png.pagespeed.ic.V0cVgp99SN.png
As on my layout ill be having another textview just before the checkbox as well. Also ill be adding a dynamic button at the footer.
Now i dont want the users to interact with my listview. Only the button should be clickable and when they click it i want to run some calculations and show them in the relevant "result" textview and to check the checkbox next to it to show that i have calculated it. Meaning i have to access each and every "result" textview and "check" checkbox in the code.
Please provide me some guidance for coding this app. Im fed up looking through very complex codes trying learn on my own. Many many thanks for your help.
Shavinka
Check out below links...
ListView + CheckBox =?
How to get checked items from android listview?
http://sunil-android.blogspot.in/2013/04/android-listview-checkbox-example.html
http://fundoocode.net/android-listview-checkbox-example-onitemclicklistener-and-onclicklistener/
http://www.mysamplecode.com/2012/07/android-listview-checkbox-example.html
I have a listview where each item has 2 images, one on the right and the other on the left. Between them there is a textview that is filled from data. If text is long then it can continue down but there is a lot of free space just as you can see in the image. I want to use this space also to display text. I have been looking around the web and I have seen things like this http://code.google.com/p/android-flowtextview/downloads/detail?name=FlowTextDemo.zip&can=2&q= but this is useless. I don't want to lose the control of the images because I need their click method. What is the best way to do it? I have thought that maybe I can put a textview between images and an other down and when the first is filled continue in the second one but how can I know how many letters can keep the first textview?
I don't understand why FlowTextView (that you linked to) won't work for you. It's derived from RelativeLayout and flows text around any child views. The child views can be your images, positioned as you normally would in a RelativeLayout. Their onClick methods should work just fine.
<com.pagesuite.flowtext.FlowTextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/the_text >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="onTopLeftClick"
android:src="#drawable/top_left_image" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:onClick="onTopRightClick"
android:src="#drawable/top_right_image" />
</com.pagesuite.flowtext.FlowTextView>
You will need to set the text in code, or else extend FlowTextView and define your own custom attribute(s) to do it from xml.
I have an app where i am displaying dynamic text in a TextView. The text is has
text_view.setMovementMethod(new ScrollingMovementMethod());
text_view.setMovementMethod(LinkMovementMethod.getInstance());
Within the text in the TextView i have html links around particular words. The links work, however as you scroll with your finger down the page, you will sometimes accidentally click the link and be redirected on accident.
The issue seems to be that the word that is the link, is not the only thing that becomes clickable. It appears that the entire line on the page becomes a link.
Example text in the TextView:
TEAM1 # TEAM2
STATUS: FINAL
LINK: ESPN
The "ESPN" is suppose to be the only item in the list that is clickable.
Do you have any ideas on how to correct this?
Addition:
Here is my layout xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:orientation="vertical"
android:visibility="visible" >
<ImageButton
android:id="#+id/refresh"
android:layout_width="30dp"
android:layout_height="28dp"
android:layout_gravity="right"
android:src="#drawable/ic_menu_refresh"
android:visibility="visible" />
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget_date"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:textSize="12dp"
android:visibility="visible" />
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16dp"
android:visibility="visible" />
</LinearLayout>
Then in my code i am setting the html links around the word ESPN as such:
Loop through data and create dynamic link based on data append to larger string, the string scores set in the TextView below is just a string that contains the string "link" in html format.
String link = "LINK: " + "ESPN<BR><BR>");
text_view.setText(Html.fromHtml(scores));
When all is said and done i have what i need. Only problem is when you start to use your finger to scroll down the page, you will sometimes kick off the link due to the fact that it appears that the link spans the entire row, including the blank spaces. So your finger accidentatily hits a link everyone once in a while. All i want is for the link to only kick off when you specifically click on the word "ESPN" not on the white space.
Changing the string to actually include spaces after the closing tag, made the white space no longer clickable.
"LINK: " + "ESPN <BR><BR>");
strange band aid but it works.
Per Lt. Tuvok (since he didn't close it...): The string that i end up passing to the TextView, although it contains html elements it is not html. If i include spaces after the closing tag, the white space is no longer clickable and you can only go to the link if you click on "ESPN". Ill post above what i did. Dont think its a permanent solution just a band aid.