T
T
TaTIk942016-09-01 18:11:46
Java
TaTIk94, 2016-09-01 18:11:46

Can't extract data from putExtra?

there are 2 Activities, I want to transfer data from the first Activity list View through intent to 2 Activities using this method:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(MainActivity.this, about.class);
        switch (position) {
            case 0:
            intent.putExtra("key1", getResource().getString(R.string.tekst1));
            break;
            case 1:
            intent.putExtra("ke2", getResource().getString(R.string.tekst2));
            break ;
            case 2:
            intent.putExtra("key3", getResource ().getString(R.string.tekst3));
            break ;
        }
        startActivity (intent) ;
    }
});

And this is how I tried to extract it in the second activity:
Intent intent = getIntent();
Bundle extras = intent.getExtras();
switch(i) {
    case 0:
        TextView.setText(extras.getString("key1"))
        break;
    case1:
        textview.setText(extras.getString("key2"))
        break;
    case2:
        texView.setTex(extras.getString("key3"))
        break;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Serkov, 2016-09-01
@TaTIk94

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(MainActivity.this, about.class);
        switch (position) {
            case 0:
            intent.putExtra("key", getResource().getString(R.string.tekst1));
            break;
            case 1:
            intent.putExtra("key", getResource().getString(R.string.tekst2));
            break ;
            case 2:
            intent.putExtra("key", getResource ().getString(R.string.tekst3));
            break ;
        }
        startActivity (intent) ;
    }
});

Intent intent = getIntent();
Bundle extras = intent.getExtras();
TextView.setText(extras.getString("key"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question