1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
public class MainActivity extends Activity implements OnClickListener{
private String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu","Fedora", "CentOS", "LinuxMint", "Debian",
"Windows7", "Mac OS X", "Linux", "OS/2" };
private PersonnalArrayAdapter adapter;
private ListView listView;
private int currentIndexSelection = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.adapter = new PersonnalArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, this.values);
this.listView = (ListView) findViewById(R.id.listView1);
this.listView.setAdapter(this.adapter);
this.listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
((Button) findViewById(R.id.buttonNext)).setOnClickListener(this);
((Button) findViewById(R.id.buttonPrevious)).setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.buttonNext:
this.currentIndexSelection++;
this.listView.smoothScrollToPosition(this.currentIndexSelection);
this.adapter.setSelectedPosition(this.currentIndexSelection);
break;
case R.id.buttonPrevious:
this.currentIndexSelection--;
this.listView.setSelection(this.currentIndexSelection);
this.listView.smoothScrollToPosition(this.currentIndexSelection);
this.adapter.setSelectedPosition(this.currentIndexSelection);
break;
}
}
} |
Partager