A
A
Andres Iniesta2018-06-02 07:49:11
Android
Andres Iniesta, 2018-06-02 07:49:11

Does the listview disappear when you navigate back to the previous activity?

I have 3 Activities:
On the main, when the application starts, a selection is made in the listview, then when you click on any element of this lv, a new activity opens and another selection is made in the new listview by the value of the pressed element. Further, when you click on an element in the textview on the third Activity, infa comes out.
And so:
When from Activity #3 you go back on 2 Activity all is empty. And when from the second to the first you go lv in place with a selection.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rostislav, 2018-06-19
Makkall @viogull

The second activity does not receive anything from the first? Show a code fragment with the opening of the 2nd activity and its onCreate() method.

A
Andres Iniesta, 2018-06-19
@nuroraf

Joe Ballad
Gets the value of the listView row that was clicked by the user.

lvAuthorsAndPoems.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

                Intent intent = new Intent(MainActivity.this, AuthorSelectedActivity.class);
                intent.putExtra("authorName", authorPoemsList.get(position).getAuthorName());
                startActivity(intent);
            }
        });

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authorselected);

        lvAuthorSelected = (ListView) findViewById(R.id.lvAuthorSelected);
        dbHelper = new DatabaseHelper(this);
        arrayList = new ArrayList();

        Intent intent = getIntent();
        authorName = intent.getStringExtra("authorName");
        setTitle(authorName);

        dbHelper.openDatabase();
        Cursor cursor = dbHelper.mDatabase.rawQuery("SELECT p.description FROM poem p, authors a WHERE p.authorID=a._id AND a.authorName LIKE '%" + authorName + "%'",null);
        cursor.moveToFirst();
        while(!cursor.isAfterLast()){
            arrayList.add(cursor.getString(0));
            cursor.moveToNext();
        }
        cursor.close();

        arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);
        lvAuthorSelected.setAdapter(arrayAdapter);
        dbHelper.closeDatabase();


        lvAuthorSelected.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Intent iPoemText = new Intent(AuthorSelectedActivity.this, PoemTextActivity.class);
                iPoemText.putExtra("description", arrayAdapter.getItem(i));
                iPoemText.putExtra("authorName", authorName);
                startActivity(iPoemText);
            }
        });

    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question