Listview to cardview in android - android

now I just got listview in android layout now i want to add cardview to this to show list of cardview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/clistview">
</ListView>
</LinearLayout>
//java code
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(ActivityCourseListView.this, android.R.layout.simple_list_item_1,adapterlist);
clistview.setAdapter(adapter);
Log.e("Course ListView","Courses"+adapterlist);

You can't do this with a normal list view. You have to use a custom listview for this. Here is a tutorial
https://www.youtube.com/watch?v=By_1tpPDt4g

Related

Android RecyclerView scrollbar doesn't work

the scrollbar in my RecyclerView doesn't work, I mean I can scroll the RecyclerView with touch, I also can see the scrollbar but it's can not move
Before ask the question I also tried with some answers here for example:
https://www.dev2qa.com/android-recyclerview-horizontal-scroll-example/
Android RecyclerView Scroll not working after Layout edit
But none of them work for me
Below is my code, thanks in advance
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HexViewActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_hex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:scrollbarSize="15dp"
android:scrollbars="vertical" />
</ScrollView>
Code to create the view
RecyclerView recyclerView = findViewById(R.id.rv_hex);
recyclerView.setLayoutManager(new LinearLayoutManager(HexConstant.app_ontext));
m_fileDataAdapter = new FileDataAdapter(HexConstant.app_ontext, files[0]);
recyclerView.setAdapter(m_fileDataAdapter);
recyclerView.setNestedScrollingEnabled(true);
Is there any example for Scrollbar + recyclerView, pls let me know
Change the outer layout with scroll view layout.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HexViewActivity">
<!-- Your stuff here -->
</ScrollView>
Have you tried using RecyclerView's attribute app:fastScrollEnabled="true"?
Check the full answer here. https://stackoverflow.com/a/46026362/6455501

How to add three items in same row in navigation drawer?

I have navigation drawer. In which i have one header and other is items list.
Now the problem is how to add three items in a same row.Like
Header xyz
--------------------------
Image Text Text -----> row one
-----------------------------
iamge text text ------> row two
----------------------------
image text text ------> row three
---------------------------
----- ....... so on
And when user click on the any item of the list that item should display on the header. Please guide me.
You should create your custom navigation drawer then you can achieve your requirement. for more follow this tutorial http://www.tutecentral.com/android-custom-navigation-drawer/
May this help you.
1.Use NavigationView
2.Add layout to NavigationView
3.add RecyclerView to layout (and set GridLayoutManager)
The important is use inflateHeaderView method in your code .
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="true">
<FrameLayout
android:id="#+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="#dimen/dp_200"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/white"
android:paddingTop="#dimen/dp_25"/>
</android.support.v4.widget.DrawerLayout>
header_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:id="#+id/tv_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
activity
View headview = mNavigationView.inflateHeaderView(R.layout.header_layout);
TextView tvHeader = (TextView) headview.findViewById(R.id.tv_header);
RecyclerView recyclerView = (RecyclerView) headview.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(this,3));
recyclerView.setAdapter(mAdapter);

Android-Last item of the ListView is not visible

I have added the ListView inside ViewPager, as soon as the page is loaded the first tab is selected and the last item of the list does not show up for the first time, its becoming visible when I go to next tab and come back. I would like to see all the items of the listview when its loaded for the first time. Please help me to fix this problem.
This is the xml for the listview -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview_categories"
android:layout_width="fill_parent"
android:divider="#color/light_gray_a1"
android:dividerHeight="0.667dp"
android:background="#color/white"
android:layout_height="fill_parent" />
</RelativeLayout>
add bottom padding like this and change fill_parent to match_parent
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview_categories"
android:layout_width="match_parent"
android:divider="#color/light_gray_a1"
android:dividerHeight="0.667dp"
android:paddingBottom="40dp"
android:background="#color/white"
android:layout_height="match_parent" />
</RelativeLayout>
I had this issue. Just now I solved it. Look for android:layout_weight in all the Layouts you used and if it is set some non zero values like android:layout_weight="1" or android:layout_weight="0.91", then set them to zero like this,
android:layout_weight="0"

How to dynamically change text of empty view in listfragment

I have red many solutions regarding this but none of them solved my problem.
What i want to do is, when my list view is empty its ok if the default empty text view shows up (which is declared in xml) but what if i want to change its text at some point in an activity that extends listfragment according to my need and make it visible....
Recently i tried this:
public void setEmptyText(CharSequence emptyText) {
ListView mListView = (ListView) NotificationsView.findViewById(android.R.id.list);
View emptyView = mListView.getEmptyView();
((TextView) emptyView).setText(emptyText);
}
It doesn't give any error but it is not solving the problem too. Any Help would be appreciated thanks
EDIT:
here is my layout of listfragment
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/fragment_bg"
android:divider="#null"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_style" >
</ListView>
<TextView
android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/fragment_bg"
android:text="No data" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
If you are using ListFragment all you need to do is call the method
setEmptyText("Your empty text"):
The system will recognize the view label with the android:id="#id/android:empty" id and will change the text for you. No need to reference it or do any cast, it's all built in the ListFragment
By default the listview or adapter (don't remember which one) makes it invisible. Call emptyView.setVisibility(View.VISIBLE); to make it visible.
This is how to change the value of a text view:
TextView tv = (TextView) findViewById(R.id.empty);
tv.setText('yourText');

ListView inside Fragment android

Im having trouble with implementing list view inside a fragment.
the xml code is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/jo_logo" />
</LinearLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
simple ImageView and afterwards the list view.
I've already tried to implement:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(),
android.R.layout.simple_list_item_1, viewList);
setListAdapter(adapter);
where viewList is View[], on the onCreateView function.
seems that it's not working that way inside fragment.
thing is i need that the first view will be ImageView and second one is ListView, and all inside the Fragment.
please help, thank in advance, udi
In your layout xml change android:id="#+id/listView1" to android:id="#android:id/list" otherwise the ListActivity / ListFragment won't find your ListView.

Categories

Resources