.:: Jasa Membuat Aplikasi Website,Desktop,Android Order Now..!! | | Order Now..!! Jasa Membuat Project Arduino,Robotic,Print 3D ::.

Dynamic change the content of Spinner

0 komentar


بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh

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.
package com.AndroidListSpinner;
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;
List myList1, myList2;
private ArrayAdapter myAdapter1, 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();
}
}
Xml Code









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
NB :: Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI), Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :

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 :

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh


Artikel Dynamic change the content of Spinner, Diterbitkan oleh scodeaplikasi pada Kamis, 24 Januari 2013. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code ,Dengan Cara menghubungi saya Ke Email: Fajarudinsidik@gmail.com, atau No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.

Tawk.to