Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BasicoActivity extends ActionBarActivity {
- ListView lv1;
- Cursor words;
- MyDatabase db;
- String LOG_TAG = "myLogs";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_basico);
- final ActionBar actionBar = getSupportActionBar();
- actionBar.setHomeButtonEnabled(true);
- actionBar.setDisplayHomeAsUpEnabled(true);
- lv1 = (ListView) findViewById(R.id.lv1);
- db = new MyDatabase(this);
- words = db.getWords();
- startManagingCursor(words);
- SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
- R.layout.item_lesson,
- words,
- new String[]{"word", "trans_w"},
- new int[] {R.id.espUnit, R.id.rusUnit});
- lv1.setAdapter(adapter);
- lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> av, View v, int position, long id) {
- Log.d(LOG_TAG, "itemClick: position = " + position + ", id = " + id);
- Intent intent1 = new Intent(BasicoActivity.this, TabsActivity.class);
- startActivity(intent1);
- }
- });
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/espUnit"
- android:layout_marginTop="10dp"
- android:layout_marginLeft="10dp"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/rusUnit"
- android:layout_marginBottom="10dp"
- android:layout_marginLeft="10dp"/>
- <?xml version="1.0" encoding="utf-8"?>
- <ListView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/lv1"
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- tools:context=".BasicoActivity"/>
- @Override
- public void onItemClick(AdapterView<?> av, View v, int position, long id) {
- Intent intent = new Intent(BasicoActivity.this, TabsActivity.class);
- intent.putExtra("pos",position); // прикрепляем к интенту передаваемые данные с ключом "pos"
- startActivity(intent);
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- int position = getIntent().getExtras().getInt("pos");
- }
- Bundle bundle = new Bundle();
- bundle.putInt("pos", position);
- fragment.setArguments(bundle);
- Bundle bundle = getArguments();
- int position = bundle.getInt("pos", -1); // -1 - значение по умолчанию, если ничего не было получено.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement