I'm storing miliseconds from alarms to database and database has them all stored correctly since I test it displaying them in a single TextView and it displays them all. But my ListView only displays miliseconds value which has 8 numbers, when there are 9 number or more it doesn't display them. Here is my ListView :
<?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:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="250dp" >
</ListView>
</LinearLayout>
My xml I use for rows :
<?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:orientation="vertical" >
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="45dp" />
</LinearLayout>
Method that I use for populating the ListView :
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = DatabaseManager.getAllData();
startManagingCursor(c);
String[] from = new String[] { DatabaseManager.TABLE_COLUMN_TWO };
int[] to = new int[] { R.id.text1 };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
Please replace the Listview with following code. Its working good.Don't fix the height of the Listview in android:layout_heightPlease replace your layout xml code with the following xml.
<?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:orientation="vertical" > <ListViewandroid:id="#android:id/list"android:layout_width="match_parent"android:layout_height="match_parent" ></ListView></LinearLayout>
Related
I would like to create my custom list view of items in my database. Unfortunately when I try to declare SimpleCursorAdapter it can't find my custom list.
There is fragment when I declare SimpleCursorAdapter :
cursor = db.query("SERIAL",new String[]{"_id","NAZWA","SERWIS"},null,null,null,null,null);
if(cursor.moveToFirst())
{
SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this, android.R.layout.my_custom_list,
cursor,
new String[]{"NAZWA","SERWIS"},
new int[]{android.R.id.text1,android.R.id.text2},
0);
listViewSeriale.setAdapter(listAdapter); // List listViewSeriale = (ListView) findViewById(R.id.listViewSeriale);
}
It work for simple_list_item_2 but I have more items in my database than two...
content_activity_baza_danych.xml <-- file where is id listViewSeriale :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listViewSeriale" />
my_custom_list.xml :
<?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="wrap_content"
android:orientation="vertical"
android:textAlignment="gravity"
>
<TextView
android:id="#+id/textNazwa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textSerwis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
Error:
error: cannot find symbol
SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this, android.R.layout.my_custom_list,
^
symbol: variable my_custom_list
I think solution is very simple but I'm new in android and don't understand many things.
It should be R.layout.my_custom_list and not android.R.layout.my_custom_list as when you say android.** you are referencing the android package and not your package.
Hey how do I space out items in a recyclerview, I am currently using an array in java to provide the images and the names of the objects, however, it wont let me use padding to space out the items in my list??
<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"
tools:context="com.athena.athenafront.NavigationFragment"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#android:color/white">
<!-- TODO: Update blank fragment layout -->
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primaryColor"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/drawer_recyclerview"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:choiceMode="singleChoice"
android:dividerHeight="0dp"
android:background="#ffff"
android:layout_height="400dp">
</android.support.v7.widget.RecyclerView>
Here is my java
public static List<AthenaPanel> getData() {
//created an object for ur Drawer recyclerview array
List<AthenaPanel> data= new ArrayList<>();
//this is where you would add all your icons for the drawer list
//arrays of icons
int[] icons={R.mipmap.ic_launcher};
String[] titles = {"Explore","Myprofile","MyStatus","Calendar","Setting","Send FeedBack"};
//this is our for loop to cycle through the icons and the titles
for(int i=0;i<5;i++){
AthenaPanel current=new AthenaPanel();
//i%().length allows ups to loop over the array any number of times we want to
current.iconId=icons[i%icons.length];
current.title=titles[i%titles.length];
data.add(current);
}
return data;
}
To add the space on the RV itself do this:
On your RecyclerView xml, use this: android:padding="8dp" or any other value that you like. Along with android:clipToPadding="false".
E.g.:
<android.support.v7.widget.RecyclerView
android:id="#+id/drawer_recyclerview"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:choiceMode="singleChoice"
android:dividerHeight="0dp"
android:background="#ffff"
android:layout_height="400dp"
android:clipToPadding="false"
android:padding="8dp">
</android.support.v7.widget.RecyclerView>
More info on that here.
To add space on the RV items, you'll have to edit the XML files of your item row and add the margin/padding there.
EDIT: Maybe this question is related.
I'm trying to use an ArrayAdapter in a ListActivity:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.id.text1, new String[] { "a", "b"});
setListAdapter(adapter);
This is the layout:
<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" >
<TextView
android:id="#id/android:text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_below="#id/android:text1" >
</ListView>
</RelativeLayout>
None of the solutions I found on StackOverflow seems to work. I'm using API 10. Can you help please?
You are using the wrong type of resource, you need to reference R.layout not R.id. Try android.R.layout.simple_list_item_1:
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] { "a", "b"});
Define a layout for the rows of your ListView, and call it, for example, simple_list_item_1 (create the file simple_list_item_1.xml in the folder res/layout). Put your TextView into this layout:
<?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" >
<TextView
android:id="#id/android:text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</RelativeLayout>
and then create your ArrayAdapter like this:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.text1, new String[] { "a", "b"});
Here you'll find a detailed explanation about Lists and Adapters.
I have made a list view containing two childs. Now i am trying to append a series of children to each of these two childs.
I am using following procedure.
super.onCreate(savedInstanceState);
setContentView(R.layout.report_main_layout);
CharSequence[] dummyChar = {"a","b"};
listView = (ListView) findViewById(R.id.UIMainAccountListView);
adapter = new CustomArrayAdapterOfMainList(this, dummyChar);
listView.setAdapter(adapter);
In the custom adapter i am using following code.
if (position == 0)
{
viewHolder.listView = (ListView) view.findViewById(R.id.UIReportTrialBalanceListView);
adapter = new CustomArrayAdapterForChildList(context, debitAccounts,sumDebit);
viewHolder.listView.setAdapter(adapter);
}
else
{
viewHolder.listView = (ListView) view.findViewById(R.id.UIReportTrialBalanceListView);
adapter = new CustomArrayAdapterForChildList(context, creditAccounts, sumCredit);
viewHolder.listView.setAdapter(adapter);
}
All i am getting is like this, I want to extend it so that all of the accounts show, List view should wrap content but it is not wrapping content
This will stack two listviews and force them to take up half of their parent each.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="2">
<ListView
android:id="#+id/list1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<ListView
android:id="#+id/list2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
You can remove the cache color by setting android:cacheColorHint="#android:color/transparent" for each listview
<?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:orientation="vertical"
android:paddingBottom="20sp" >
<ListView
android:id="#+id/child1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/child2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/child1" />
</RelativeLayout>
This layout for first child1 listview above the second child2 listview
Thanks
I have a ListView that uses SimpleAdapter, each row has 2 TextViews, and I would like to use an external font to one of the two TextView.. Here is the code of the class:
public class QuranEnglish extends Activity {
<...>
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.quran_english);
listview=(ListView) findViewById(R.id.QuranEnglishListView);
<..add into list..>
SimpleAdapter adapter = new SimpleAdapter(
this,
list,
R.layout.quran_english_row,
new String[] {"Arabic","English"},
new int[] {R.id.QuranEnglishTextViewArabic,R.id.QuranEnglishTextViewEnglish});
listview.setAdapter(adapter);
xml for each row (quran_english_row.xml):
<?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" android:orientation="vertical">
<LinearLayout android:gravity="right" android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_width="fill_parent">
<TextView android:textSize="21px" android:text="TextView" android:id="#+id/QuranEnglishTextViewArabic" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<TextView android:textSize="21px" android:text="TextView" android:id="#+id/QuranEnglishTextViewEnglish" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
xml for the layout (quran_english.xml):
<?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" android:orientation="vertical">
<ListView android:id="#+id/QuranEnglishListView" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>
</LinearLayout>
So how can I put the external typeface of the TextView that is in the row (quran_english_row.xml)? I tried using this line though it crashed my application:
((TextView) findViewById(R.id.QuranEnglishTextViewArabic)).setTypeface(Typeface.createFromAsset(getAssets(),"dejavusans.ttf"));
R.id.QuranEnglishTextViewArabic
is not an id of one of your views here. It is an id of a example view, which is used to fill the list. In order to change the font, you need to get one view of your list. This works if you have chosen one of your views:
TextView view = getSelectedView();
if (view != null) {
view.setTypeface(Typeface.createFromAsset(getAssets(),"dejavusans.ttf"));
}