Layout for a League table - android

I'm having some issue creating a layout for a league table. In my current layout, i have created a table with consists of two rows. The first row has the headings i want, and the second row has black fields that consist of the data that is obtained. I get the data from my server which contains an xml file. The problem i am having is not getting the data as i can do that.. The problem is that when i display the data i use a ListAdapter which need a layout linked to it. But when i link the appropriate layout, i get a repeat of header after every line... e.g.
TEAM P W L D P
Arsenal 1 1 1 1 1
TEAM P W L D P
Aston Villa 1 1 1 1 1
I'm sure its a simple error to fix.... maybe i have to you something else to display the data???
Below is the code for the main
public class tab_1 extends ListActivity {
public int a = Football_appActivity.league;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listplaceholder);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
if(a==1){
String xml = XMLfunctions.getXML_prem_table();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);
if((numResults <= 0)){
Toast.makeText(tab_1.this, "League Table", Toast.LENGTH_LONG).show();
finish();
}
NodeList nodes = doc.getElementsByTagName("team");
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("id", XMLfunctions.getValue(e, "id"));
map.put("name", "" + XMLfunctions.getValue(e, "name"));
map.put("played", "" + XMLfunctions.getValue(e, "played"));
map.put("won", "" + XMLfunctions.getValue(e, "won"));
map.put("drawn", "" + XMLfunctions.getValue(e, "drawn"));
map.put("lost", "" + XMLfunctions.getValue(e, "lost"));
map.put("points", "" + XMLfunctions.getValue(e, "points"));
mylist.add(map);
}
**
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main_tab,
new String[] { "name", "played", "won", "drawn", "lost", "points"},
new int[] { R.id.item_title, R.id.item_played, R.id.item_won,
R.id.item_drawn, R.id.item_lost, R.id.item_points});**
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
#SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(tab_1.this, o.get("name") + " have Won '" + o.get("won") + "' games, and are currently on '" + o.get("points") + "' points!", Toast.LENGTH_LONG).show();
}
});
}
Below is the layout called main_tab.xml
<?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"
android:padding="7dp"
>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:id="#+id/table123">
<TableRow>
<TextView
android:text="Name"
android:id="#+id/team_title">
</TextView>
<TextView android:text="P "
android:gravity="right"
android:id="#+id/team_played">
</TextView>
<TextView android:text="W"
android:id="#+id/team_won">
</TextView>
<TextView android:text="D"
android:id="#+id/team_drawn">
</TextView>
<TextView android:text="L"
android:id="#+id/team_lost">
</TextView>
<TextView android:text="P"
android:id="#+id/team_points">
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textSize="20dp" />
<TextView
android:id="#+id/item_played"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_won"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_drawn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_lost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_points"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
</TableRow>
</TableLayout>
</LinearLayout>
Below is the loyout for ListPlaceHolder.XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
<TextView
android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="No data">
</TextView>
</LinearLayout>
Ok cool.. so i have changed the layout of the main_tab.xml and created a new layout called table_header.xml That contains the headings for the league e.g. Name, Played, Won, Lost etc... But now i have an error in the logcat.. Below is the code what for main page...
if(a==1){
String xml = XMLfunctions.getXML_prem_table();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);
if((numResults <= 0)){
Toast.makeText(tab_1.this, "League Table", Toast.LENGTH_LONG).show();
finish();
}
NodeList nodes = doc.getElementsByTagName("team");
setContentView(R.layout.table_header);
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("id", XMLfunctions.getValue(e, "id"));
map.put("name", "" + XMLfunctions.getValue(e, "name"));
map.put("played", "" + XMLfunctions.getValue(e, "played"));
map.put("won", "" + XMLfunctions.getValue(e, "won"));
map.put("drawn", "" + XMLfunctions.getValue(e, "drawn"));
map.put("lost", "" + XMLfunctions.getValue(e, "lost"));
map.put("points", "" + XMLfunctions.getValue(e, "points"));
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main_tab,
new String[] { "name", "played", "won", "drawn", "lost", "points"},
new int[] { R.id.item_title, R.id.item_played, R.id.item_won,
R.id.item_drawn, R.id.item_lost, R.id.item_points});
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
#SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(tab_1.this, o.get("name") + " have Won '" + o.get("won") + "' games, and are currently on '" + o.get("points") + "' points!", Toast.LENGTH_LONG).show();
}
});
The line for changing the layout i have used is:
setContentView(R.layout.table_header);
is this correct????
The first error i get is (there is a long list, but i think this is the cause):
04-15 09:46:42.268: E/AndroidRuntime(346): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.julian.football_app/com.julian.football_app.tab_1}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

As you suspected, your problem is here:
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main_tab,
new String[] { "name", "played", "won", "drawn", "lost", "points"},
new int[] { R.id.item_title, R.id.item_played, R.id.item_won,
R.id.item_drawn, R.id.item_lost, R.id.item_points});
Specifically this:
R.layout.main_tab
That is supposed to be the list row layout. Since you provided that with header and data, it is repeating the header for each list line. Separate them. You need to create a layout for JUST the list. Basically remove the second TableLayout from that file, put it in it's own XML file and call that one for your list adapter. Add your ListView underneath the header table layout in main_tab.
row_layout.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textSize="20dp" />
<TextView
android:id="#+id/item_played"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_won"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_drawn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_lost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
<TextView
android:id="#+id/item_points"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="13dp" />
</TableRow>
</TableLayout>

Related

Listview with linear straight progressbars

I'm new to android and now trying to make a small project.
It includes a listview with textviews and a linear progressbar (its value doesn't need to change).
Simple Adapter was used to fill data to textviews.
But to set progressbar value, which adapter should be used.
I can't image how to set value to progressbar.
Please help with this.
Here is my code:
main.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">
<ListView
android:id="#+id/dblist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector" />
</LinearLayout>
list_row.xml
<?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="wrap_content"
android:background="#drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="#drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="#+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
<!-- Title Of Song-->
<TextView
android:id="#+id/col1tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail"
android:text="Rihanna Love the way lie"
android:textColor="#040404"
android:typeface="sans"
android:textSize="15dip"
android:textStyle="bold"/>
<!-- Artist Name -->
<TextView
android:id="#+id/col2tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/col1tv"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="#+id/thumbnail"
android:text="Just gona stand there and ..." />
<TextView
android:id="#+id/package_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/col1tv"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="#+id/col2tv"
android:text=" puzzles, 0 solved" />
<!-- Rightend Duration -->
<!-- Rightend Arrow -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
main.java
String[] from = new String[] {"id", "name", "size"};
int[] to = new int[] { R.id.id, R.id.name, R.id.size };
// prepare the list of all records
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < pkg_id_col.size(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", id_col.get(i));
map.put("name", name_col.get(i));
map.put("size", size.get(i));
fillMaps.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list_row_add_new, from, to);
lv_add_new.setAdapter(adapter);
The SimpleAdapter knows how to bind data only for TextViews and ImageView. To bind your ProgressBar use a SimpleAdapter.ViewBinder:
String[] from = new String[] {"id", "name", "size", "progress"};
int[] to = new int[] { R.id.id, R.id.name, R.id.size, R.id.theIdOfTheProgressBar}; // it seems that you don't have a `ProgressBar` in the layout
// prepare the list of all records
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < pkg_id_col.size(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", id_col.get(i));
map.put("name", name_col.get(i));
map.put("size", size.get(i));
map.put("progress", valueForProgressBar); // progress will hold the progress for your ProgressBar
fillMaps.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list_row_add_new, from, to);
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view.getId == R.id.theIdOfTheProgressBar) {
((ProgressBar) view).setProgress(Integer.parseInt(data));
return true;
}
return false;
}
});

Showing Alphabet Index in android listview

I have created listview and i want to implement sectionindexer and alphabetIndexer in my listview.
I am reffering http://www.anddev.org/tutalphabetic_fastscroll_listview_-_similar_to_contacts-t10123.html. That works excellent. But for my code , i am not getting how to implement that functionality.
here is my list_item.xml code :
<?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="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="#drawable/list_selector"
android:padding="5dp"
android:id="#+id/tab">
<LinearLayout android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="#+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="#drawable/musicsymbol"/>
</LinearLayout>
<TextView
android:id="#+id/songTitle"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_alignTop="#+id/thumbnail"
android:color="#10bcc9"
android:maxLines="1"
android:layout_toRightOf="#+id/thumbnail"
/>
<TextView
android:id="#+id/duration"
android:layout_width="56dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/songTitle"
android:gravity="right"
android:layout_marginRight="5dip"
android:textSize="15dip"
android:textColor="#10bcc9"
android:textStyle="bold"
android:maxLines="1"
/>
<TextView
android:id="#+id/songArtist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/songTitle"
android:textSize="14dp"
android:color="#10bcc9"
android:textStyle="bold"
android:lines="1"
android:layout_toRightOf="#+id/thumbnail"
/>
My JAVA code :
Cursor cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null , null, null,MediaStore.Audio.Media.TITLE );
if (cursor == null)
{
//Query Failed , Handle error.
}
else if (!cursor.moveToFirst())
{
//No media on the device.
}
else
{
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Audio.Media.DATA);
int artistcolumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
int durationcolumn =cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DURATION);
for(int i=0;i<cursor.getCount();i++)
{
String thisTitle = cursor.getString(titleColumn);
String path = cursor.getString(idColumn);
String artist = cursor.getString(artistcolumn);
Long duration = cursor.getLong(durationcolumn);
Utilities objUtilities = new Utilities();
String timeDuration = objUtilities.milliSecondsToTimer(duration);
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle",thisTitle);
song.put("songPath", path);
song.put("artist", artist);
song.put("duration",timeDuration);
// Adding each song to SongList
songsList.add(song);
cursor.moveToNext();
}
}
// looping through playlist
for (int i = 0; i < songsList.size(); i++) {
// creating new HashMap
HashMap<String, String> song = songsList.get(i);
// adding HashList to ArrayList
songsListData.add(song);
}
// Adding menuItems to ListView
String[] from = {"songTitle", "artist" , "duration"};
int[] to={R.id.songTitle,R.id.songArtist, R.id.duration};
adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, from, to);
setListAdapter(adapter);
so how to implement sectionindexer with my this listadapter. Please suggest me some solution. Thanx.
You can use this library. This is the simplest Section Adapter available for Android's ListView.

Android ListView Multiple Columns from an Array

I have a list view with following row template.
<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout android:clickable="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/android_btn_large" android:gravity="center_vertical"
android:layout_weight="1">
<TextView android:id="#+id/txtLeftButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="#+id/imgLeftButton"
android:text="Riverside Park" android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"></TextView>
<ImageView android:id="#id/imgLeftButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toLeftOf="#id/txtLeftButton"
android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:layout_alignParentRight="true" android:src="#drawable/plus_icon_480">
</ImageView>
</RelativeLayout>
<RelativeLayout android:clickable="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/android_btn_large" android:gravity="center_vertical"
android:layout_weight="1">
<TextView android:id="#+id/txtRightButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="#+id/imgRightButton"
android:text="Riverside Park" android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"></TextView>
<ImageView android:id="#id/imgRightButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toLeftOf="#id/txtRightButton"
android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:layout_alignParentRight="true" android:src="#drawable/plus_icon_480">
</ImageView>
</RelativeLayout>
</LinearLayout>
And the data is stored in a List as...
List<String[]> rows = new ArrayList<String[]>();
rows.add(new String[] { "id", "name" });
I want to know what Adapter I should use to fill the ListView with these rows assuming I need 2 column data in a single row?
Just use a SimpleAdapter with a list of HashMap
ListView list = (ListView) findViewById(R.id.ListView01);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", "1");
map.put("name", "bob");
mylist.add(map);
//Each row is a new hashmap
map = new HashMap<String, String>();
map.put("id", "2");
map.put("name", "sally");
mylist.add(map);
//ect...
mSchedule = new SimpleAdapter(this, mylist, R.layout.listrow,
new String[] {"id", "name"}, new int[] {R.id.txtID, R.id.txtName});
list.setAdapter(mSchedule)
You could implement the ListViewAdapter interface in a class and inflate the row-xml in the getView-method. You can use a regular activity with a simple LinearLayout and a list view in it.

Fix the image in the background of list activity

Hello I have called a image behind the listview and listview is transparent. Each record in the list is appearing on repeating image . how i can fix this repeat ion of image . Here is the xml 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"
android:padding="7dp"
android:background="#drawable/ac"
android:cacheColorHint="#00000000"
>
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textSize="20dp" />
<TextView
android:id="#+id/item_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="18dp" />
</LinearLayout>
Thanks
Now i have updated xml files like this
main xml 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"
android:background="#drawable/ac"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView android:id="#+id/listView"
android:background="#drawable/ac"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
List xml 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"
android:cacheColorHint="#00000000"
>
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textSize="20dp" />
<TextView
android:id="#+id/item_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="18dp" />
</LinearLayout>
and in the activity calling in this way
{ R.id.item_title, R.id.item_subtitle }
the whole code looks like
public class Test extends ListActivity {
Prefs myprefs = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listplaceholder);
this.myprefs = new Prefs(getApplicationContext());
// install handler for processing gui update messages
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions.getJSONfromURL("...............");
try{
JSONArray earthquakes = json.getJSONArray("services");
for(int i=0;i<earthquakes.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = earthquakes.getJSONObject(i);
map.put("id", e.getString("taskid"));
map.put("pic", "Service name : " + e.getString("employeepic"));
map.put("serviceinfo", "" + e.getString("employeename")+ " : "+ e.getString("starttime")
+" To " + e.getString("endtime"));
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.test,
new String[] { "servicename", "serviceinfo" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
#SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(Test.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
I suppose you are using the above XML to populate the items in the list view (i.e) inside getView() ...
1. Remove android:background="#drawable/ac" from the above XML.
2. Add it to the ListView's XML say,
<ListView android:id="#+id/listView"
android:background="#drawable/ac"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Explanation:
Setting Background to the layout that you are using to populate the list will produce 'repeating image' because you are setting background to the child (i.e) the listView's item and not to the List.
EDIT:
1.For your Activity, you will be loading the ListView from an Layout File(say main.xml), inside that layout file for the ListView add the background.
2. Remove the background from the LinearLayout in your above code.
Edit Again:
use the following XML,
main.xml
<?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"
android:background="#drawable/ac"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView android:id="#+id/listView"
android:background="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
List xml 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"
android:cacheColorHint="#00000000"
android:background="#00000000"
>
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textSize="20dp" />
<TextView
android:id="#+id/item_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="18dp" />
</LinearLayout>

How to make a android interface with "football league table" style?

I need to show a football league table on my app. Like this: http://www.fuencalientedelapalma.org/sitios/Fuencaliente/VF7/PublishingImages/Clasificacion.png
As you see i need to do some kind of Android XML layout that shows 9 columns, and 10 rows, plus one more row for the name of the column.
I read all the documentation of listview on the android developers guide, but i can't find the way to do it. And also i search on google and i can't find the way to do it.
Code examples are welcome
thanks
You can use listView like this, inflating you own listlayout :
maListViewPerso = (ListView) findViewById(R.id.listviewperso);
ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for (int i = 0; i<statDB.getListStat().size(); i++){
Stat stat= statDB.getListStat().get(i);
listId.add(statDB.getListStat().get(i).getId()+"");
String message = " Chiffre d'affaire : "+statDB.getListFinancier(stat.getId()+"").get(0).getCaBrut()+" euros";
map = new HashMap<String, String>();
titre
map.put("titre", stat.getDate());
map.put("description", message);
map.put("img", String.valueOf(R.drawable.icon_crisalid));
map.put("stat_in",""+statDB.getListStat().get(i).getId());
listItem.add(map);
}
statDB.close();
SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.listview,
new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
maListViewPerso.setAdapter(mSchedule);
maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
#Override
#SuppressWarnings("unchecked")
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
Intent intent=new Intent().setClass(ListActivity.this, DetailActivity.class);
intent.putExtra("stat_in", map.get("stat_in") );
intent.putExtra("listId",listId);
startActivity(intent);
}
});
this is my listview code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="20px"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="10px"
android:layout_weight="1"
>
<TextView android:id="#+id/titre"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16px"
android:textStyle="bold"
android:textColor="#color/textcol"
/>
<TextView android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="12px"
android:textColor="#color/textcol"
android:paddingRight="10px"
/>
</LinearLayout>
and this is how I check the listview :
<?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"
android:background="#color/backgroundcolor"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:paddingTop="5px"
android:paddingBottom="5px"
android:background="#drawable/bg2"
>
<TextView
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
/>
</LinearLayout>
<ListView
android:id="#+id/listviewperso"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
you just have to adapt the listview.

Categories

Resources