Here is my problem. How to make text don't wrap?
I already tried to make text smaller. Didn't work. Tried to do singleline="true". Here is what he do(2 screen shot 6-7 textview)
1 Screenshot) Here is I made it in the Eclipse
2 Screenshot) Here is how it showen in the emulator
Try setting android:ellipsize to none for each TextView. For more details see documentation on this attribute.
From xml:
<TextView ... android:ellipsize="none" />
From code:
TextView textView = new TextView(context);
...
textView.setEllipsize(null);
try giving android:maxLines=1... singleLine property should also work...
Related
I am making an android app where the same imageview is displayed every time the user enters a value. but I want the imageview to be changed every time the user enters a value. I wrote a code to do this but the problem is after the first image is displayed I face black screen and it takes me to the first page in the app, it doesn't crash just shows black screen.
here is the imageview code in xml file:
<ImageView
android:id="#+id/ImageSuccess"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:layout_marginTop="20dip"
android:scaleType="centerInside"
android:src="#drawable/image1" />
and here where I changed the imageview in java file:
ImageView myImage= (ImageView) findViewById(R.id.ImageSuccess);
if(userVlue.equals("SCHOOL")){
myImage.setImageResource(R.drawable.image1);
}
else if(userVlue.equals("CAR")){
myImage.setImageResource(R.drawable.image2);
}
else if(userVlue.equals("TOY")){
myImage.setImageResource(R.drawable.image3);
}
One of myImage or userVlue is not set properly and probably is null.
Debug and share logs. Your partcular activity is getting distroyed probably because of nullpointexception hence returning to main activity in backtrack.
I tried with a sample app and your logic is working perfectly.
You are handling user action on some UI element, when you do findViewById, cotext is that UI element, so this method searches ImageSuccess in children of it. Try giving page layout as rootlayout and do rootlayout.findViewById("ImageSuccess");
I found the solution finally, the black screen appeared because the images were only in the drawable file, so I needed to add the images in all drawbridge folders such as drawable-ldp, drawable-ldpi etc...., so that the app can work in different phone sizes.
I am using a LikeView in my android application and want to change the button size. Changing the view's size using layout parameters or the width/height at addView() does not help.
I'm using libGDX and have never worked with XML + libGDX, so a way to do it with code only would be nice!
Does anyone know how to do this? Currently I use the following code to create my LikeView:
likeButton = new LikeView(application);
likeButton.setLikeViewStyle(LikeView.Style.BUTTON);
likeButton.setX(x);
likeButton.setY(y);
likeButton.setObjectId(LIKE_URL);
likeButton.setVisibility(View.GONE);
application.layout.addView(likeButton,width,height);
likeButton.invalidate();
application.layout is a RelativeLayout
Try to create your LikeView from XML (or inflate this layout at runtime):
<com.facebook.widget.LikeView
android:id="#+id/button_like"
android:layout_height="31dp"
android:layout_width="wrap_content" />
I finally fixed it using setScale on the view. It's not the most elegant solution, but it does the job.
likeButton.setScaleX(1.8f);
likeButton.setScaleY(1.8f);
I have a TextView with links and other text. I need to links to be clickable & I need to capture the click and open the link in a webview in my activity. I followed this this answer. My code looks like this:
actitivity_main.xml
<TextView android:id="#+id/textlinktest"
android:layout_width="wrap_content"
android:layout_height="50dp"/>
And this is the way I invoke it:
textLinkTest.setText(Html.fromHtml("Something else google"));
textLinkTest.setText(RichTextUtils.replaceAll(
(Spanned) textLinkTest.getText(),
URLSpan.class,
new URLSpanConverter()));
The links show up fine, but they are not clickable! The onclick in my customeclickablespan never gets called. I tried toggling android:linksClickable & also tried different values for android:autoLink. But the links remain unclickable. Any thoughts?
Add
textLinkTest.setMovementMethod(LinkMovementMethod.getInstance());
before
textLinkTest.setText(RichTextUtils.replaceAll((Spanned) textLinkTest.getText(), URLSpan.class, new URLSpanConverter()));
I have an edittext and I would like to paste some text in it. I can copy the text from some web page but I am not able to paste the text in my edittext control.How can I enable my edittext to paste some text.Here is my main.xml for edittext ;
enter code here
<EditText
android:id="#+id/enter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight= "2"
android:scrollbars="vertical"
android:textColor="#color/black"
/>
Thanks
This is on Android 4.4.2 Samsung S4;
Documentation for TextView says that:
To allow users to copy some or all of the TextView's value and paste
it somewhere else, set the XML attribute android:textIsSelectable to
"true" or call setTextIsSelectable(true). The textIsSelectable flag
allows users to make selection gestures in the TextView, which in turn
triggers the system's built-in copy/paste controls.
There is also another Textview attribure called android:cursorVisible which determines if the system should be invoked about the copy/paste callbacks.
By default I believe both of these are true and selection/copy/paste mechanics are already enabled. I could not change that behaviour by using android:textIsSelectable="false" but if I set android:cursorVisible="false" initially you can't paste anything inside the EditText. Only after you type something in, cursor and selection behaviour becomes enabled again. Maybe this should be handled inside the code rather than in the layout xmls, or it might be related to android:inputType which also did not make a difference for me.
So try setting android:cursorVisible="true" in your EditText's layout xml if paste is not enabled by default.
According to your problem if you copied some data any where in your system and you want to paste it in some specific variable, like Edit TextBox, Textview etc, then this code will surely help you.
ClipboardManager clipMan = (ClipboardManager)getSystemService(v.getContext().CLIPBOARD_SERVICE);
myEdtTxt.setText(clipMan.getText());
Note:- here the clipMan object will store the data whenever copied process take place and we will return that data from that object and will set it,
To enable the standard copy/paste for TextView, U can choose one of the following:
Change in layout file:
Either add below property to your TextView
android:textIsSelectable="true"
and In your Java class write this line to set it programmatically.
myTextView.setTextIsSelectable(true);
if fragment try with
mContext.myTextView.setTextIsSelectable(true);
And long press on the TextView you can see copy/paste action bar.
Try setting the inputType="text" for the EditText field
I am creating an application in android. And when I try running the app after inserting an ImageView control into my app, I am getting the following error in logCat:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.bdisys.android.wsaccess/com.bdisys.boinfoportal.ui.FirstAppUI}:
java.lang.ClassCastException: android.widget.TextView
The following came like a warning after I had inserted an ImageView into my layout/main.xml.
The following classes could not be found:
- ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)
Following the xml code portion after I had inserted the ImageView.
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/favicon" />
</TableRow>
Can anyone tell why this error comes?
Am not getting any idea about this. Please help. Thanks in advance.
You are triying to cast a TextView into ImageView. Check your resource xml.
I had the same problem with the ImageView, the message The following classes... was showing up in the design tab of my main.xml
In my case the problem was that the drawable had no extension, however it appeared in #drawable/ section and was appearing in the autocomplete too as if nothing was wrong.
Cannot provide any info on the classcast exception though.
To sum up: Make sure your favicon file has the correct extension
if you have code like this
ImageView img;
img = (ImageView) findViewById(R.id.TextView1);
change to
TextView txt;
txt = (TextView) findViewById(R.id.TextView1);