Reputation: 24492
I have a ListView, that like any other ListView, show one item each row.
I'm trying to make this ListView show 2 items each row, somethings like this:
I'm already using custom JSON Adapter to show listview results from JSON API. My goal is to show an imageview each 1/2 row (each item).
Any ideas?
Upvotes: 1
Views: 7465
Reputation: 5420
You are actually talking about a GridView
with android:numColumns="2"
in the xml.
or
You can use,
gridview.setNumColumns(2);
programmatically.
The only challenge I see is (sort of but no) displaying the it like,
1 0
3 2
5 4
...
But you can handle that behavior in your adapter, if you want to know how, let me know.
Upvotes: 2
Reputation: 234
One thing you might want to look into is using a GridView instead of a ListView for this. You can explicitly set the number of columns to 2.
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:scrollbarStyle="outsideOverlay"
android:verticalScrollbarPosition="right"
android:scrollbars="vertical">
</GridView>
Upvotes: 1
Reputation: 20221
Use a GridView with numColumns
= 2
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gridview"
android:numColumns="2"
/>
Upvotes: 6