Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a ListView below with an ArrayAdapter to make a simple List view with corresponding Html elements added to assets folder.


Is there a way to Change Class variable from inner Method
java android xml android-studio
I have a ListView below with an ArrayAdapter to make a simple List view with corresponding Html elements added to assets folder.

import android.app.ListActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.Toast;

import android.content.Intent;


public class MainActivity extends ListActivity

{


String indx;

    String[] values = { "index", "Prooo", "My Android Examples","My Android Tutorials","My Android Pages", "My Android Favorites"};



    @Override

    public void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);



        // parameters are (Context, layout for the row, and the array of data)

        setListAdapter(new ArrayAdapter<String>(this,

                                                android.R.layout.simple_list_item_1, values));

    }

    
    @Override

    public void onListItemClick(ListView l, View v, int position, long id)

    {
        indx = (String) getListAdapter().getItem(position);
        Toast.makeText(this,indx,Toast.LENGTH_SHORT).show();
        Intent i=new Intent(MainActivity.this,WebViewActivity.class);
        startActivity(i);

    }
    
    
    



}


What I have tried:

Everything else works fine but the aim is to change the String indx value with the item Position returned by onListItemClick as each Html document's name is the same as that of each String values item.

I tired to access indx from a class WebViewActivity to display the Html but the String indx value is still Null.

I would've specify something like Public indx if it was Python please is there any way to change Indx like that in Java and I can't use return because void cannot return
Posted
Comments
Richard MacCutchan 20-Jun-20 9:00am    
All I can see above is two methods, either of which can set the value of the indx variable. What exactly is not working?
David Crow 20-Jun-20 23:00pm    
"I tired to access indx from a class WebViewActivity..."

Which you did not show.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900