Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. private String[] Numbers =
  2. {"1", "2", "3", "4","5",
  3. "6", "7", "8", "9", "10"};
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9.  
  10. ListView myList=(ListView) findViewById(R.id.listView1);
  11.  
  12.  
  13. ArrayAdapter<String> dataAdapter=new ArrayAdapter<String>
  14. (this, android.R.layout.simple_list_item_1, android.R.id.text1, Numbers);
  15.  
  16.  
  17. myList.setAdapter(dataAdapter);
  18.  
  19. lv.setOnItemClickListener(new OnItemClickListener() {
  20.  
  21. @Override
  22. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
  23. long arg3) {
  24. int finalAns=0;
  25. for (int i = 1; i <= arg2; i++) {
  26. finalAns+=i;
  27. }
  28. Intent inte= new Intent(getApplicationContext(),YoursecondActivity.class);
  29. inte.putExtra("FinalValue", ""+finalAns);
  30. startActivity(inte);
  31. }
  32. });
  33.  
  34. @Override
  35. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
  36. long arg3) {
  37. // TODO Auto-generated method stub
  38.  
  39. Intent i = new Intent(getApplicationContext(), Second.class);
  40. startActivity(i);
  41.  
  42. }
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement