API Demos

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

API Demos

Postby darolla » Wed Oct 08, 2008 12:00 pm

Hi,

the API Demos have a very simple layout. it's just buttons one below the other, with no border and just small lines as separator.

how can I just do this? which layout? which properties for the buttons?

thanks & greetings,
marco
Attachments
device.png
device.png (10.81 KiB) Viewed 451 times
User avatar
darolla
Master Developer
Master Developer
 
Posts: 273
Joined: Thu Sep 25, 2008 5:16 pm
Location: Dortmund, Germany

Top

Postby MrSnowflake » Wed Oct 08, 2008 1:55 pm

If I recall correctly (I a little too lazy atm) this is just a ListView.

And why don't you take a look in the ApiDemos yourself? code is in the SDK! There are a lot of cool apps there.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby darolla » Thu Oct 09, 2008 8:11 am

hi,

is there a tutorial for this special listview?

its not that simple to understand it nor to find tutorials...

greetings,
marco
User avatar
darolla
Master Developer
Master Developer
 
Posts: 273
Joined: Thu Sep 25, 2008 5:16 pm
Location: Dortmund, Germany

Postby MrSnowflake » Thu Oct 09, 2008 8:26 am

This isn't a special ListView, it's just an oridinary ListView. I suspect you want some more information about the Adapter, correct?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby darolla » Thu Oct 09, 2008 12:19 pm

I've found this on the internet.

But to be honest I didnt get everything, altough this example is a little more than I need...


CustomList.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package aexp.customlist;
  2.  
  3.  
  4.  
  5. import android.app.ListActivity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.widget.SimpleAdapter;
  10.  
  11. import android.view.Menu;
  12.  
  13. import android.view.MenuItem;
  14.  
  15.  
  16.  
  17. import java.util.ArrayList;
  18.  
  19. import java.util.HashMap;
  20.  
  21.  
  22.  
  23. public class CustomList extends ListActivity {
  24.  
  25.         ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
  26.  
  27.         private static final int ADD_ITEM_ID = 1;
  28.  
  29.  
  30.  
  31.         public void onCreate(Bundle icicle) {
  32.  
  33.                 super.onCreate(icicle);
  34.  
  35.                 setContentView(R.layout.main);
  36.  
  37.                 SimpleAdapter notes = new SimpleAdapter(this, list,
  38.  
  39.                                 R.layout.main_item_two_line_row, new String[] { "line1",
  40.  
  41.                                                 "line2" }, new int[] { R.id.text1, R.id.text2 });
  42.  
  43.                 setListAdapter(notes);
  44.  
  45.         }
  46.  
  47.  
  48.  
  49.         public boolean onCreateOptionsMenu(Menu menu) {
  50.  
  51.                 boolean result = super.onCreateOptionsMenu(menu);
  52.  
  53.                 menu.add(0, ADD_ITEM_ID, Menu.NONE, R.string.add_item);
  54.  
  55.                 return result;
  56.  
  57.         }
  58.  
  59.  
  60.  
  61.         public boolean onOptionsItemSelected(MenuItem item) {
  62.  
  63.                 switch (item.getItemId()) {
  64.  
  65.                 case ADD_ITEM_ID:
  66.  
  67.                         addItem();
  68.  
  69.                         break;
  70.  
  71.                 }
  72.  
  73.                 return super.onOptionsItemSelected(item);
  74.  
  75.         }
  76.  
  77.  
  78.  
  79.         private void addItem() {
  80.  
  81.                 long ts = System.currentTimeMillis();
  82.  
  83.                 int lastDigit = (int) (ts % 10);
  84.  
  85.                 HashMap<String, String> item = new HashMap<String, String>();
  86.  
  87.                 item.put("line1", Long.toString(ts));
  88.  
  89.                 item.put("line2", "lastDigit: " + Integer.toString(lastDigit));
  90.  
  91.                 list.add(item);
  92.  
  93.                 SimpleAdapter notes = new SimpleAdapter(this, list,
  94.  
  95.                                 R.layout.main_item_two_line_row, new String[] { "line1",
  96.  
  97.                                                 "line2" }, new int[] { R.id.text1, R.id.text2 });
  98.  
  99.                 setListAdapter(notes);
  100.  
  101.         }
  102.  
  103. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


main.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.         android:orientation="vertical" android:layout_width="fill_parent"
  6.  
  7.         android:layout_height="fill_parent">
  8.  
  9.  
  10.  
  11.         <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
  12.  
  13.                 android:layout_height="fill_parent" />
  14.  
  15.  
  16.  
  17.         <TextView android:id="@+id/android:empty"
  18.  
  19.                 android:layout_width="fill_parent" android:layout_height="fill_parent"
  20.  
  21.                 android:text="@string/main_no_items" />
  22.  
  23.  
  24.  
  25. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


main_item_two_line_row.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.         android:layout_width="fill_parent" android:layout_height="wrap_content"
  6.  
  7.         android:orientation="vertical">
  8.  
  9.  
  10.  
  11.         <TextView android:id="@+id/text1" android:textSize="16px"
  12.  
  13.                 android:textStyle="bold" android:layout_width="fill_parent"
  14.  
  15.                 android:layout_height="wrap_content" />
  16.  
  17.  
  18.  
  19.         <TextView android:id="@+id/text2" android:textSize="12px"
  20.  
  21.                 android:textStyle="italic" android:layout_width="fill_parent"
  22.  
  23.                 android:layout_height="wrap_content" />
  24.  
  25. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


greetings,
marco
User avatar
darolla
Master Developer
Master Developer
 
Posts: 273
Joined: Thu Sep 25, 2008 5:16 pm
Location: Dortmund, Germany

Postby MrSnowflake » Thu Oct 09, 2008 12:28 pm

This looks like the NotePad tutorial of the Android docs. I sugest you peek through it, as it explains how to use the SimpleCursorAdapter and selecting items from the list using the SimpleCursorAdapter.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests