Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. public class BasicoActivity extends ActionBarActivity {
  2.  
  3. ListView lv1;
  4. Cursor words;
  5. MyDatabase db;
  6. String LOG_TAG = "myLogs";
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_basico);
  12.  
  13. final ActionBar actionBar = getSupportActionBar();
  14. actionBar.setHomeButtonEnabled(true);
  15. actionBar.setDisplayHomeAsUpEnabled(true);
  16.  
  17. lv1 = (ListView) findViewById(R.id.lv1);
  18. db = new MyDatabase(this);
  19. words = db.getWords();
  20. startManagingCursor(words);
  21.  
  22. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
  23. R.layout.item_lesson,
  24. words,
  25. new String[]{"word", "trans_w"},
  26. new int[] {R.id.espUnit, R.id.rusUnit});
  27. lv1.setAdapter(adapter);
  28.  
  29. lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  30. @Override
  31. public void onItemClick(AdapterView<?> av, View v, int position, long id) {
  32.  
  33. Log.d(LOG_TAG, "itemClick: position = " + position + ", id = " + id);
  34.  
  35.  
  36. Intent intent1 = new Intent(BasicoActivity.this, TabsActivity.class);
  37. startActivity(intent1);
  38. }
  39. });
  40. }
  41. }
  42.  
  43. <?xml version="1.0" encoding="utf-8"?>
  44. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  45. android:orientation="vertical" android:layout_width="match_parent"
  46. android:layout_height="match_parent">
  47.  
  48. <TextView
  49. android:layout_width="match_parent"
  50. android:layout_height="wrap_content"
  51. android:id="@+id/espUnit"
  52. android:layout_marginTop="10dp"
  53. android:layout_marginLeft="10dp"/>
  54. <TextView
  55. android:layout_width="match_parent"
  56. android:layout_height="wrap_content"
  57. android:id="@+id/rusUnit"
  58. android:layout_marginBottom="10dp"
  59. android:layout_marginLeft="10dp"/>
  60.  
  61. <?xml version="1.0" encoding="utf-8"?>
  62. <ListView
  63. android:layout_width="match_parent"
  64. android:layout_height="wrap_content"
  65. android:id="@+id/lv1"
  66. xmlns:android="http://schemas.android.com/apk/res/android"
  67. xmlns:tools="http://schemas.android.com/tools"
  68. tools:context=".BasicoActivity"/>
  69.  
  70. @Override
  71. public void onItemClick(AdapterView<?> av, View v, int position, long id) {
  72.  
  73. Intent intent = new Intent(BasicoActivity.this, TabsActivity.class);
  74. intent.putExtra("pos",position); // прикрепляем к интенту передаваемые данные с ключом "pos"
  75. startActivity(intent);
  76. }
  77.  
  78. @Override
  79. public void onCreate(Bundle savedInstanceState) {
  80. super.onCreate(savedInstanceState);
  81.  
  82. int position = getIntent().getExtras().getInt("pos");
  83. }
  84.  
  85. Bundle bundle = new Bundle();
  86. bundle.putInt("pos", position);
  87. fragment.setArguments(bundle);
  88.  
  89. Bundle bundle = getArguments();
  90. int position = bundle.getInt("pos", -1); // -1 - значение по умолчанию, если ничего не было получено.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement