Here is my code:
public void openBottomSheet(long id) {
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
_bottomSheet.setState(BottomSheetBehavior.STATE_EXPANDED);
_bottomSheet.setPeekHeight(140);
coordinatorLayout.requestLayout();
Item item = _selected.getItem(id);
final String titleText = item.getTitleText();
_bottomSheetTitle.setText(titleText);
coordinatorLayout.requestLayout();
int imageResource = (id > 5) ? R.drawable.ic_closed : R.drawable.ic_open;
_bottomSheetState.setBackgroundResource(imageResource);
coordinatorLayout.requestLayout();
coordinatorLayout.invalidate();
}
Firstly, I'm broadly having the issue described at https://code.google.com/p/android/issues/detail?id=205226 where they suggested requestLayout() was the solution.
And it does sort of fix it. However, I am finding the first time I open the bottom sheet (by clicking some other element in the UI) the text does not load. The second, third, fourth and so on time, the text does update. So it's just on that initial load that it's not quite working.
The image resource seems to load fine on the first attempt. It's just the textview not updating.
Does anyone have any suggestions?
Edit
I've tried putting the requestLayout() in a number of places to see if it would make a difference.
Related
I am using the <TimePicker> widget to enable the user to set the time.
However, since I'm embedding the <TimePicker> into one of my views, I'd like to get rid of the TimePicker's header (the crossed out area in the picture).
Default timepicker in Android looks like this:
Question: Is it possible to remove the timepicker's header and use only the analog part of the widget?
There is no public method in TimePicker to directly hide or show the Time Header. Try the below source code will give us the name of the resource ID for that View, which we can get with the system Resources. Then finding the View, and setting its visibility to GONE.(I haven't tested)
private void hideTimeHeaderLayout(TimePicker picker) {
final int id = Resources.getSystem().getIdentifier("time_header", "id", "android");
final View timeLayout = picker.findViewById(id);
if(timeLayout != null) {
timeLayout .setVisibility(View.GONE);
}
}
I have a ScrollView containing a TextView. I linkify parts of that TextView with
Pattern pattern = Pattern.compile("MyLink");
Linkify.addLinks(textView1, pattern, "mylink://");
I habe an Intent filter in my Manifest for mylink:// so a new Activity is opened when MyLink is clicked (as described in this question).
This works most of the time, sometimes though a click on the MyLink portion of the TextView doesn't open the Activity but only scrolls the ScrollView in which my TextView resides to the top.
Where does this behaviour come from and how can I fix it?
If you are attempting to open a link that leads to your current activity, it might be recreating the same activity and gives the sensation that it's scrolling up. Probably you want to modify your manifest and set the activity's launchMode attribute to singleTask
Why dont you use TextViewWithLinks?
With that you can have two types of click on the textview,
1. On TextView
2. On Link TextView
String text = "bananas on www.bananas.ba and Google";
TextViewWithLinks textview = new TextViewWithLinks(this);
textview.setText(Html.fromHtml(text));
textview.linkify(new TextViewWithLinks.OnClickLinksListener() {
#Override
public void onTextViewClick() {
// Do whatever you want
}
#Override
public void onLinkClick(String url) {
// Do whatever you want
}
});
//SET Colors
textview.setLinkColors(Color.RED, Color.BLACK);
setContentView(textview);
Let me know if this is not resolving your issue.
Enjoy Coding... :)
Robotium 4.1 doesn't seem to have any features (that work with ScrollView rather than ListView objects) that scroll to a certain point and then stop. My problem is that I need to receive the text from a TextView object that is not visible from the very top of the scrollView but also not visible from the bottom. The ScrollView object as well as the TextView object are both private in the GUI class of the target package, so receiving the string directly is not an option.
this is my attempt
solo.waitForText("Start Logging");
solo.clickOnText("Start Logging");
solo.waitForText("Performing Throughput Test");
assertEquals(
GUIHelperFunctions.isServiceRunning(GlobalVariables.getContext(),
GlobalVariables.getSERVICENAME(), true), true);
boolean inProgress = true;
while (inProgress == true){
if(!solo.searchText("Performing Throughput Test",true)){
inProgress = false;
}
}
String message = solo.getText("Upload Throughput:").getText().toString();
i found that it also fails when you exchange the final line for
assertTrue(solo.searchText("Upload Throughput:"));
In my project I have recieved the contents of several other TextViews that are also within the LinearLayout which is the direct child of the ScrollView, but all of these were visible from the very top or very bottom.
Has anyone found a way around this problem or a way to stop scrolling of a ScrollView in a certain place?
Try to use:
assertTrue(solo.waitForText("Upload Throughput:", 1, 20000, true));
before
String message = solo.getText("Upload Throughput:").getText().toString();
I have a Activity which has 2 components
Image view
Text view
Here the image in the image view is changed using a timer. This works fine. The text is scrolling text is marquee. Individually these works fine.
My problem is when the image gets changed it also reset the marquee string.
Is there any way to avoid this?
Is there any way to refresh the display partially in android.
Edit
File imgFolder = new File(config.AppDataDir+config.MainImagesDir);
if(imgFolder.isDirectory()) {
File[] imageList = imgFolder.listFiles();
if(imageList!=null) {
if(imageList.length>0) {
if(imageList[currentImageNum].exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imageList[currentImageNum++].getAbsolutePath());
ImageHolder.setImageBitmap(myBitmap);
}
if(currentImageNum>=imageList.length)
currentImageNum =0;
}
}
}
Thanks
Normally, changing the source of an ImageView should not have any implications on other views. Most probably when changing the image you are doing something that is reflected on the TextView too.
I am beginner in the android development, can any one tell me how to expand a list when I click on an element of it say an image icon.
This does it for me, due to privacy I can't write the whole code here
TextView desc = (TextView) v.findViewById(R.id.editText1);
ImageView icon = (ImageView) v.findViewById(R.id.listIcon);
if (desc.getVisibility() == View.VISIBLE) {
icon.getLayoutParams().height = heightIcon;
desc.setVisibility(View.GONE);
} else {
icon.getLayoutParams().height = LayoutParams.FILL_PARENT;
desc.setVisibility(View.VISIBLE);
}
Now when I click the icon, the text view placed below to it, becomes visible and thus has solved the question.
Take a look at ExpandableListView and ExpandableListAdapter
Here is the example code snippet to do it : ExpandableList1.java
You can even find it in your Android SDK folder
Drive:***\***\Android-sdk\samples\android-<apilevel>\ApiDemos\src\com\example\android\apis\view\ExpandableList1.java