We can change the List programmatically, to change the content of the Spinner, then call notifyDataSetChanged() of the ArrayAdapter to update the Spinner.
It's a example modify from the last post. There are two Spinner. When the Move button clicked, the current item of Spinner1 will be moved to Spinner2.
You can download the source code Spinner Dynamic Move Content
Cheers Guys!!!!!!!
It's a example modify from the last post. There are two Spinner. When the Move button clicked, the current item of Spinner1 will be moved to Spinner2.
package com.AndroidListSpinner;Xml Code
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
public class AndroidListSpinnerActivity extends Activity {
Button btnMove;
Spinner MySpinner1, MySpinner2;
ListmyList1, myList2;
private ArrayAdaptermyAdapter1, myAdapter2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnMove = (Button)findViewById(R.id.move);
MySpinner1 = (Spinner)findViewById(R.id.myspinner1);
MySpinner2 = (Spinner)findViewById(R.id.myspinner2);
initList();
myAdapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, myList1);
myAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
MySpinner1.setAdapter(myAdapter1);
myAdapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, myList2);
myAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
MySpinner2.setAdapter(myAdapter2);
btnMove.setOnClickListener(MoveOnClickListener);
}
Button.OnClickListener MoveOnClickListener
= new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int pos = MySpinner1.getSelectedItemPosition();
if(pos != AdapterView.INVALID_POSITION){
myList2.add(myList1.get(pos));
myList1.remove(pos);
myAdapter1.notifyDataSetChanged();
myAdapter2.notifyDataSetChanged();
}
}};
void initList(){
myList1 = new ArrayList();
myList1.add("Sunday");
myList1.add("Monday");
myList1.add("Tuesday");
myList1.add("Wednesday");
myList1.add("Thursday");
myList1.add("Friday");
myList1.add("Saturday");
myList2 = new ArrayList();
}
}
You can download the source code Spinner Dynamic Move Content
Cheers Guys!!!!!!!
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :