i cant add button to linear layout - android-layout

I have a listActivity that displays via an adapter an xml feed fetched from the web, adn the layout file activity_list_feed.xml :
`<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:transcriptMode="normal"
/>`
In the graphic editor i cannot drag a button into this layout, and when i try to hardcode as per this file :
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/addBtn"
android:text="Add New Item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="addItems"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:transcriptMode="normal"
/>
</LinearLayout>`
i get a compile error message :
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
How can i add a button on top of the list because i want to refresh the pull.thank you.

The code that you provided actually works in its current state in Android Studio:
Make sure that in your java code, you are referencing the correct item. Make sure that you're setting the overall layout to be that layout, and THEN doing findViewById(R.layout.addBtn).
Also, try changing the Android Version in your IDE to 22 (as I have it set in the top right corner of the picture). That may solve your error.

I managed to add the button in the editor and this without setting to API 22 as per your picture. However the program didn't compile still.
The message error "ArrayAdapter requires the resource ID to be a TextView" meant i didn't provide the right argument to the adapter.
According to this answer :
"ArrayAdapter requires the resource ID to be a TextView" xml problems
it appears that the choice of the constructor is important, since i wanted to add a button in the view, i must use the constructor with 4 arguments (the additional argument being the id of the view):
http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context,int,int,java.util.List)
Using this constructor solved the problem.

Related

EditText with hint, where hint moves

I have seen EditText that has a hint and when user taps on it the hint moves up reducing the font size and making the field editable by the user. When the user moves to another EditText leaving it blank the hint appears back in full size.
What is it and how can I add it in my activity on Android Studio using XML?
I am on Android Studio using Kotlin.
if you mean this
it is TextInputLayout
Add the dependency for the design support library inside the build.gradle (Module: app) file as shown below.
implementation 'com.google.android.material:material:<version>'
the latest version at this time is 1.2.0-alpha03 you can see latest version from mvnrepository
Then, you can use it like this in your xml layouts.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/myTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/my_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/YOUR_HINT"
android:singleLine="true"
android:textColor="#color/colorDarkestGray" />
</com.google.android.material.textfield.TextInputLayout>
This is TextInputLayout and you can use editText as child in it like this :
At first add the dependency for the design support library inside the build.gradle file as shown below.
implementation 'com.android.support:design:25.3.1'
And if you are using AndroidX use this :
implementation 'com.google.android.material:material:1.0.0'
Second ,Then implement that like this :
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/activity_horizontal_margin">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Floating Hint Enabled Default" />
</android.support.design.widget.TextInputLayout>
Android TextInputLayout Features
1-Enabling/Disabling floating hints
2-Enabling/Disabling floating hint animation
3-Displaying Error Messages
4-Showing Character Counter
5-Password Visibility Toggle and . . .

android, xmlns, No resource indentifier error

In an xml layout file, the xmlns is already defined, but I get this error at compile time: No resource identifier found for attribute. Why is that? thanks
I'm following a Facebook dev tutorial on facebook site https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ the layout file is as follows:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.facebook.widget.ProfilePictureView
android:id="#+id/profilepic"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
app:preset_size="large" app:is_cropped="true"
/>
</ScrollView>
I figured it out, have to replace /res-auto with res/com.facebook.samples.profilepicture
Your layout file looks correct. check that in your 'project.properties' file, the 'android.library.reference.1' value points to the correct location.
The res-auto is feature properly supported in API level 17. It must be applied for all layouts using custom attributes. It is automatically replaced on build time, by eclipse.
Ref Updated SDK Tools and ADT revision 17

RealPlayer like Android app layout

I am new to Android and I am trying to design my Android application like the interface of the Android RealPlayer but I have no idea how!
What I exactly want to design is: Break the page into 4 equal grid-like sections such that the whole page is covered and no extra empty space is left at the end of the page (exactly like the RealPlayer interface).
<?xml version="l.0" encoding="utf—8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android“
android:id=“#+id/gridview“
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_weight="l.0"
android:columnWidth="90dp"
android:horizontalSpacing="l0dp"
android:numColumns="2"
android:orientation="horizontal"
android:paddingTop="50dp"
android:stretchMode=“columnWidth"
android:verticalSpacing="l0dp" >
</GridView>
I have tried manipulating GridView attributes but it seems that it is not possible only using GridView elements. I hope my problem statement is clear enough! Can somebody give me a hint on how to do that?
I have found out that it is possible using buttons of different sizes!

Android: SlidingDrawer with bottomOffset and content visible

I have been experiencing some issue with the SlidingDrawer in Android. I am building a screen with a horizontal sliding drawer. It is working fine, it is opening and closing as expected. I have set a bottomOffset as 50dip in order to see 50dpi of the content when the drawer is closed, but this is not happening.
When the drawer is closed, I am seeing the 50dip distance between the right side of the screen to the handle, but then the content view gets invisible so there is a 50dip black space between the handle and the screen edge, as the image below shows:
When I press the handle button, it seems that the content gets its visibility changed to visible, and then it appers. I would like to keep the content visible without having to press the handle, like in the imagem below:
I downloaded the SlidingDrawer source code from http://blog.sephiroth.it/2011/03/29/widget-slidingdrawer-top-to-bottom/ in order to try to change the code and get the expected result, but I am not getting.
The XML for the sliding drawer:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<br.com.dina.partial.example.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/br.com.dina.partial.example"
android:id="#+id/map_slider"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
my:handle="#+id/Handle"
my:content="#+id/ViewLayout"
my:direction="rightToLeft"
my:bottomOffset="-65dip"
android:layout_below="#+id/test">
<Button android:id="#+id/Handle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="handle"/>
<LinearLayout android:id="#+id/ViewLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.markupartist.android.widget.ActionBar
android:id="#+id/actionbar"
style="#style/ActionBar"/>
<FrameLayout android:id="#+id/ViewContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" />
</LinearLayout>
</br.com.dina.partial.example.MultiDirectionSlidingDrawer>
</RelativeLayout>
Is there a way to achieve what I want?
Many thanks
edited to add the xml
Use the onDrawerScrollListener, onDrawerOpenListener, and onDrawerCloseListener to change the visibility of certain items depending on the state of the drawer. So when you say "the drawer is closed...and the content view is invisible" then in your onDrawerCloseListener set the content view to VISIBLE. Give this a try and let me know how it goes.
EDIT so you did something like this?:
drawer.setOnDrawerCloseListener(new OnDrawerCloseListener(){
#Override
public void onDrawerClosed() {
//get the ViewContent by id and set visibility to VISIBLE
});

`VideoView.start()` cause other views to break

When my activity receives a new intent via onNewIntent, it updates the data of three Views, an ImageView, a TextView, and a VideoView. The problem is, the two other views just flash, then disappear when my VideoView comes on. After scattering a few breakpoints, I discovered that they appear when their content is set, but disappear when VideoView.onStart() is called in my MediaPlayer.onPrepared() method. I also have an AlertDialog show up when the menu button is pressed. After pressing the menu button, it shows up. I'm on Android API 9, as this is the API on the device I'm working on. I really need help, so I'd appreciate any advice.
Here's the layout. I don't think it's the issue though:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true" >
<TextView
android:id="#+id/marquee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="#android:style/TextAppearance.Large"
android:textColor="#android:color/white" >
</TextView>
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="#id/marquee"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical" />
<VideoView
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/marquee"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toLeftOf="#+id/image" />
</RelativeLayout>
Take note that the TextView is meant to be a marquee; it's supposed to keep scrolling sideways, until it is disposed of. I discovered that when the text is too short for it to start the marquee, the TextView AND the ImageView disappear (as stated earlier, they appear for a split second, then disappear). However, when the text causes the marquee feature to activate, everything works.
CURRENTLY:
I got it to work by calling postInvalidateDelayed(500) on my ImageView and TextView after calling VideoView.start(). I think the start() method is causing the problem, and requires that other views call invalidate(). Also, for some reason, there needs to be a small delay in-between the call to start() and the call to invalidate().
The layout is the issue.
Your VideoView is declared as match_parent, match_parent, allowing it to consume the whole width and height of the screen. Since you declared it last on the xml file (You used RelativeLayout. Ordering matters), the TextView and the ImageView would be covered by the VideoView.
If you're confused,
match_parent is basically the same as fill_parent. It's just another name for fill_parent in android 2.3+
Now what can you do about it?
Reorder your views in such a way that the largest is declared first. In this case, VideoView, then ImageView, then TextView.
Also note that your ImageView has height set to fill_parent - you may not want that.
I created a method, but it seems very bad:
private void startVideo() {
this.videoView.start();
if (this.imageView != null)
this.imageView.postInvalidateDelay(500);
if (this.textView != null)
this.textView.postInvalidateDelay(500);
}
It works, but it makes me feel dirty.

Resources