i want to add another spinner on event of selecting the item in spinner

by rutu » Wed, 21 May 2008 12:18:12 GMT


Sponsored Links
 i fiends,
my program already contains an spinner i want that when a item is
selected it should open another spinner. i tried to do this but i have
to use another xml which opens the previous spinner and newer also.
so for first one i have to right the same code in the another file
again. can u suggest me ways how to do this without rewriting the code
for previous spinner again.

HERE IS THE CODE WHICH POPULATES FIRST SPINNER
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this, R.array.colors,
android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{

public void onItemSelected(AdapterView parent, View v,
int position, long id) {
// TODO Auto-generated method stub

if(s1.getSelectedItem().toString().equals("yellow")){
openNewPage();
}

public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub

}

});

private void openNewPage() {
Intent i = new Intent(this,SpinnerNavigates.class);

startSubActivity(i, ACTIVITY_NAVIGATE);
}

XML CODE FOR THIS FILE
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<Spinner android:id="@+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
/>

FOR ANOTHER FILE
<Button android:id="@+id/btnChange"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Changes"
/>


</LinearLayout>
IN SpinnerNavigates CLASS I WRITE THE CODE
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.navigate);


s1=(Spinner)findViewById(R.id.spinnerMain);
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this, R.array.colors,
android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);


s2=(Spinner)findViewById(R.id.spinnerNavigate);
ArrayAdapter<CharSequence> adapter2 =
ArrayAdapter.createFromResource(this, R.array.planets,
android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapter2);


}
THEN FOR THIS XML CODE IS IN NAVIGATE.XML FILE
<LinearLayout xmlns:android="http://schemas



Other Threads

1. adding new API : make error :41

Hi all,
      I want to add my own API's to android.
      For this thing I followed one document I got from net and according to
I added one directory called "abc" to android framework which contains three
sub directories "java", "jni"  and "libabc".

When I tried to build the source code with this added directory I got
following error:
make: *** No rule to make target
`out/target/product/generic/obj/STATIC_LIBRARIES/intermediates/a',
needed by
`out/target/product/generic/obj/SHARED_LIBRARIES/libabc_jni_intermediates/LINKED/libabc_jni.so'.
Stop.

Then I checked the libabc_jni_intermediate directory and found that LINKED
directory is missing....

The content of all this "java" directory is
"abc.java" class file
 package android.abc;

public class abc
{
 static
 {
  System.loadLibrary("abc_jni");
 }
 public native int print(int i);
 public abc()
 {
    //test
 }
}

The content of "jni" directory is one "android_abc_abc.cpp" which contains
jni layer for accesing native function.
and "Android.mk" file. The content of "Android.mk" is as given below.


ifneq ($(BUILD_WITHOUT_PV),true)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
 android_abc_abc.cpp

LOCAL_SHARED_LIBRARIES := \
 libopencoreplayer \
 libopencoreauthor \
 libandroid_runtime \
 libnativehelper \


$(warning JNI makefile)

LOCAL_STATIC_LIBRARIES := \
 libabc

LOCAL_C_INCLUDES += \
 external/tremor/Tremor \
 $(PV_INCLUDES) \
 $(JNI_H_INCLUDE) \
 $(call include-path-for, corecg graphics)

LOCAL_CFLAGS +=

LOCAL_LDLIBS := -lpthread

LOCAL_MODULE:= libabc_jni
LOCAL_PRELINK_MODULE := false
$(warning JNI makefile)

include $(BUILD_SHARED_LIBRARY)
endif

And content of "libabc" directory are "test.h" and "test.cpp" file which
defines native function along with "Android.mk".
The content of "android.mk"file is

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
 test.cpp

LOCAL_SHARED_LIBRARIES := \
 libui libcutils libutils

$(warning LIBABC make file)

LOCAL_MODULE:= libabc
LOCAL_PRELINK_MODULE := false

ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
LOCAL_LDLIBS += -ldl
endif

ifneq ($(TARGET_SIMULATOR),true)
LOCAL_SHARED_LIBRARIES += libdl
endif

LOCAL_C_INCLUDES := \
 $(call include-path-for, graphics corecg)
$(warning LIBABC make file)

#include $(LOCAL_PATH)/abc/jni/Android.mk
#include $(BUILD_STATIC_LIBRARY)
#LOCAL_BUILT_MODULE:=libabc
include $(BUILD_STATIC_LIBRARY)

Please tell me what thing is causing error....
Or if any one knows any other way to add new API to android please share it.


Thanks in advance,
Sagar

-- 

2. Services, threads and AIDL

Hi,

I'm trying to understand the concept of the above; sercices, threads
and AIDL. I understand a service, it runs in the background but in the
UI thread. I understand threads... they're threads. AIDL, another
Definition language - okay. What I don't really understand is how to
get everything happy and talking to each other.

I have a service which is required to run in a new thread (it listens
for TCP messages - this would obviously hang the ui), so presumably I
start this in a new thread. But what is the best practise here? Would
I create a new thread in the activity and call the service within that
thread, or would I call the service normally and create a new thread
in onCreate() or onStart()?

Finally.. I'm making a new thread - so presumably for the server to
actually receive a message and communicate back to the activity I need
to take advantage of the AIDL, correct? In this case, presumably my
service would implement the interface created by the AIDL?

Finally though, I've seen IntentService (http://developer.android.com/
reference/android/app/IntentService.html), and read somewhere on this
group that extending this class, rather than just Service, would
handle the threads for me.. have I understood this correctly, and if
so presumably I still need some interface created by the AIDL.

Thanks,

Ben

-- 

3. How to convert RGB565 to a bitmap file?

4. How to change Android Home screen orientation by a program

5. ssl.SSLException Not trusted server certificate httpclient

6. BackupManagerService usage & explain in Framework

7. Motorola Milestone not showing up in ddms / adb on Mac OS X Snow Leopard