Listview items not displaying the retrieved columns from database vertically - java

Using simple cursor adapter I retrieve 5 columns from a table using cursor query and display them using a listview. Everything goes well but the columns retrieved are displayed horizontally in the listview. I want them to be displayed one below the other like:
TX_UID
TX_NAME
TX_AMOUNT
TX_PARTICULARS
AND NOT LIKE (Displayed as of now):
TX_UID TX_NAME TX_AMOUNT TX_PARTICULARS
String[] from = new String[]{ vivzHelper.TX_UID,
vivzHelper.TX_NAME,vivzHelper.TX_AMOUNT,vivzHelper.TX_PARTICULARS};
int[] to = new int[]
{R.id.textView,R.id.textView2,R.id.textView3,R.id.textView5 };
SimpleCursorAdapter cursorAdapter;
cursorAdapter = new SimpleCursorAdapter(getBaseContext(),
R.layout.customgetalltxrowforeditordelete , c , from , to , 0);
thislist.setAdapter(cursorAdapter);
thislist.setAdapter(cursorAdapter);
XML Layout:
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="35dp"
android:fastScrollEnabled="false"
android:divider="#FFCC00"
android:dividerHeight="2px"
android:smoothScrollbar="true"
android:background="#drawable/my_selecter"
/>

columns retrieved are displayed horizontally in the listview. I want
them to be displayed one below the other
Problem is related to customgetalltxrowforeditordelete layout instead of ListView.
To show TextView's in ListView row Vertically. use LinearLayout with orientation attribute to vertical

In your customgetalltxrowforeditordelete xml file you need to do something like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/badge13"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#id/textView2"
android:layout_below = "#id/textView"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#id/textView3"
android:layout_below = "#id/textView2"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#id/textView4"
android:layout_below = "#id/textView3"
/>
you need to use layout_below attribute in your TextView providing top view's id in attribute.

Related

Displaying multiple lines of text on a listview

I have been reading up on simple_list_item_2 and other standardized ways of displaying multi line text on a listview but none have given me what I want. As of now I am using a custom layout for the listview, but I lack the knowledge (after reading multiple articles) on how to customize each row in the listview to display it's own line of large text, tooltip (small text), and picture.
Here is the code I am using to initalize the listview and set the adapter
//List View
final String[] itemname = {
"More Rockets",
"Better Lasers",
"Super Shield",
"Super Defense"
};
final String[] itemtip = {
"+1 attack",
"+5 attack ",
"+1 defense",
"+5 defense"
};
final ListView upgradeList = (ListView) findViewById(R.id.upgradeListView);
upgradeList.setAdapter(new ArrayAdapter<String>(
this, R.layout.program_list,
R.id.Itemname, itemname));
program_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="80dp"
android:background="#drawable/buttontemplate">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Item Name"
android:id="#+id/Itemname"
android:textSize="30sp"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/imageView"
android:layout_marginLeft="15sp" />
<ImageView
android:layout_width="30sp"
android:layout_height="30sp"
android:id="#+id/imageView"
android:src="#drawable/heart"
android:layout_marginLeft="20dp"
android:layout_alignBottom="#+id/Itemname"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Tooltip:"
android:id="#+id/toolTip"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/Itemname"
android:layout_marginLeft="20dp" />
</RelativeLayout>
Here was my idea for puting another line of text in the listview but it is not the right amount of arguments
upgradeList.setAdapter(new ArrayAdapter<String>(
this, R.layout.program_list,
R.id.Itemname, itemname, R.id.toolTip, itemtip));
Any help is very much appreciated!
-Kelton
First make a POGO class with field String itemname,String itemtip then generate the getter and setter method , then from the activity class make an arraylist of this pogo class i.e
ArrayList<MyPOGO> arraylist =new ArrayList();
MyPOGO myPogo1=new MyPogo("More Rockets","+1 attack");
MyPOGO myPogo2=new MyPogo("Better Lasers","+5 attack ");
MyPOGO myPogo3=new MyPogo("Super Shield","+1 defense");
MyPOGO myPogo4=new MyPogo("Super Defense", "+5 defense");
arraylist.add(myPogo1);
arraylist.add(myPogo2);
arraylist.add(myPogo3);
arraylist.add(myPogo);
Here your arraylist size is 4 .
Now make a baseadapter or recyler view pass this arraylist

How do I space out items in a recyclerview?

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.

Selected text alignment for Android spinner

I am trying to align selected text of a Spinner in Android. It should align to the matching indentation of the other TextView and EditText in the layout.
What I have in my layout:
http://i.imgur.com/Y5sgbsN.png
What i want to do:
http://i.imgur.com/viVHpiC.png
My Layout code:
<Spinner
android:id="#+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/TextView01"
android:layout_below="#+id/TextView01"
android:entries="#array/bank_arrays"
android:prompt="#string/bank_prompt"
android:fontFamily="arial,helvetica"
android:hint="#string/bank_prompt"
android:spinnerMode="dialog"
android:ellipsize = "none"/>
Please help me out with this UI change.
Thanks
Update 1:
Parent Layout code:
<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"
android:layout_marginBottom="14.5sp"
android:layout_marginLeft="14.5sp"
android:layout_marginRight="14.5sp"
android:layout_marginTop="14.5sp"
tools:context=".RegistrationActivity" >
This is the spinnerinflate.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinnertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#00f5ff"
android:textSize="#dimen/text_size"
android:text="Text Here" >
</TextView>
In your code you can set the custom Layout for spinner as
MyAdapter myAdapter = new MyAdapter(this, R.layout.spinnerinflate,
arraylist);
spinner.setAdapter(myAdapter);
You can use SimpleAdapter as well if you don't need to have your own adapter as below
ArrayAdapter<String> simpleadapter = new ArrayAdapter<String>(YourActivityName.this, R.layout.spinnerinflate, getResources().getStringArray(R.array.yourarray));
spinner.setAdapter(simpleadapter);
By this inflate you can do whatever formatting you want. Please let me know if it helps.
you can use this lines
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="0dp"
android:textDirection="ltr" />
and you can increase padding from left to more space

Using two listViews in one activity

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

Android ListView Background repeats background after each entry

I figured it out I was using the same layout for my on create and to show the data so it was repeating everyting.
I have a list of data showing and for some reason the background I have set looks fine but after each two text views the background is squished into a 20px window overlaying the orginal background.
My xml for my view looks like so:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:background="#drawable/patriot_bg2"
android:cacheColorHint="#00000000"
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="true"
/>
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#00000000"
android:padding="2dp"
android:textSize="20dp" />
<TextView
android:id="#+id/item_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:cacheColorHint="#00000000"
android:padding="2dp"
android:textSize="13dp" />
</LinearLayout>
Below is the Java that places the text into the text fields and adds it to the screen:
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("main_content", XMLfunctions.getValue(e, "content"));
map.put("name", XMLfunctions.getValue(e, "name"));
mylist.add(map);
}
//
ListAdapter adapter = new SimpleAdapter(ShowXMLPAR.this, mylist , R.layout.listplaceholder,
new String[] {"main_content", "name" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
its almost as if there is another listview after each set of textfields but I am not sure how to get rid of it. Please help.
I had to use a seperate layout for the ListView items so only that would repeat and not the main layout.

Categories

Resources