Dynamically Editing Tab Contents trouble

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

Dynamically Editing Tab Contents trouble

Postby jwei512 » Mon Jul 27, 2009 9:40 pm

Hello! I'm a new android developer and I was having some issues working with the findViewById call and being able to alter tab contents.

My code looks looks like

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. public class BillshrinkEntry extends TabActivity {
  5.  
  6.    
  7.  
  8.     private TabHost mTabHost;
  9.  
  10.    
  11.  
  12.     @Override
  13.  
  14.     public void onCreate(Bundle savedInstanceState) {
  15.  
  16.         super.onCreate(savedInstanceState);
  17.  
  18.         setContentView(R.layout.main);
  19.  
  20.        
  21.  
  22.         mTabHost = getTabHost();
  23.  
  24.         TabSpec call_tab = mTabHost.newTabSpec("tab_test1").setIndicator("", getResources().getDrawable(R.drawable.phone_icon)).setContent(R.id.tab_1);
  25.  
  26.         createCallTab();
  27.  
  28.         TabSpec contact_tab = mTabHost.newTabSpec("tab_test2").setIndicator("", getResources().getDrawable(R.drawable.addr_book_icon)).setContent(R.id.tab_2);
  29.  
  30.         mTabHost.addTab(call_tab);
  31.  
  32.         mTabHost.addTab(contact_tab);
  33.  
  34.         mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Find Plan").setContent(R.id.tab_3));
  35.  
  36.        
  37.  
  38.         mTabHost.setCurrentTab(0);
  39.  
  40.     }
  41.  
  42.  
  43.  
  44.     private void createCallTab() {
  45.  
  46.         AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.auto_contact_edit);
  47.  
  48.         ContactListAdapter adapter = CallTab.createContactListAdapter(getApplicationContext());
  49.  
  50.         textView.setAdapter(adapter);
  51.  
  52.     }
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


and my XML file looks like

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  
  3.  
  4. <?xml version="1.0" encoding="utf-8"?>
  5.  
  6. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.    android:id="@android:id/tabhost"
  9.  
  10.    android:layout_width="fill_parent"
  11.  
  12.    android:layout_height="fill_parent">
  13.  
  14.     <LinearLayout
  15.  
  16.        android:orientation="vertical"
  17.  
  18.        android:layout_width="fill_parent"
  19.  
  20.        android:layout_height="fill_parent">
  21.  
  22.         <TabWidget
  23.  
  24.            android:id="@android:id/tabs"
  25.  
  26.            android:layout_width="fill_parent"
  27.  
  28.            android:layout_height="wrap_content" />
  29.  
  30.         <FrameLayout
  31.  
  32.            android:id="@android:id/tabcontent"
  33.  
  34.            android:layout_width="fill_parent"
  35.  
  36.            android:layout_height="fill_parent">
  37.  
  38.             <LinearLayout
  39.  
  40.                android:id="@+id/tab_1"
  41.  
  42.                android:layout_width="fill_parent"
  43.  
  44.                android:layout_height="fill_parent">
  45.  
  46.                 <TextView
  47.  
  48.                         android_id="@+id/call_tab_text"
  49.  
  50.                         android:layout_width="wrap_content"
  51.  
  52.                         android:layout_height="wrap_content"
  53.  
  54.                         android:text="Calling... " />
  55.  
  56.                 <AutoCompleteTextView
  57.  
  58.                         android_id="@+id/auto_contact_edit"
  59.  
  60.                         android:layout_width="fill_parent"
  61.  
  62.                                         android:layout_height="wrap_content" />
  63.  
  64.             </LinearLayout>
  65.  
  66.             <LinearLayout
  67.  
  68.                android:id="@+id/tab_2"
  69.  
  70.                android:layout_width="fill_parent"
  71.  
  72.                android:layout_height="fill_parent">
  73.  
  74.                 <TextView
  75.  
  76.                                         android:layout_width="wrap_content"
  77.  
  78.                                         android:layout_height="wrap_content"
  79.  
  80.                                         android:text="TEST" />
  81.  
  82.             </LinearLayout>
  83.  
  84.             <TextView
  85.  
  86.                android:id="@+id/tab_3"
  87.  
  88.                android:layout_width="fill_parent"
  89.  
  90.                android:layout_height="fill_parent"
  91.  
  92.                android:text="this is a third tab" />
  93.  
  94.         </FrameLayout>
  95.  
  96.     </LinearLayout>
  97.  
  98. </TabHost>
  99.  
  100.  
  101.  
  102.  
Parsed in 0.006 seconds, using GeSHi 1.0.8.4


Right now at this line

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.auto_contact_edit);
  5.  
  6.  
  7.  
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


it is returning null and I think that's where the problem is. Anyone think they can help me wire this stuff up?

Thanks!
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Postby jwei512 » Tue Jul 28, 2009 12:33 am

Just kidding I figured it out...

android_id="@+id/auto_contact_edit"

Guess I accidentally put a _ instead of a : ... what a waste of time sigh

Any who when I run this now and I try the auto complete it throws me a:

java.lang.IllegalStateException: get field slot from row 0 col 5 failed

My call tab looks like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. public class CallTab{
  5.  
  6.  
  7.  
  8.     public static ContactListAdapter createContactListAdapter(Context context) {
  9.  
  10.         Cursor C = context.getContentResolver().query(People.CONTENT_URI, ContactListAdapter.PEOPLE_PROJECTION, null, null, People.DEFAULT_SORT_ORDER);
  11.  
  12.         ContactListAdapter adapter = new ContactListAdapter(context, C);
  13.  
  14.         return adapter;
  15.  
  16.     }
  17.  
  18. }
  19.  
  20.  
  21.  
  22.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


And the ContactListAdapter is the same one as:

http://developer.android.com/guide/samp ... lete4.html

Any ideas what this error means? I tried googling it and it doesn't seem like much has been written about it.

Thanks again.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests