adebayaish Ответов: 0

Есть ли способ изменить переменную класса из внутреннего метода


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);

    }
    
    
    



}


Что я уже пробовал:

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

Richard MacCutchan

Все, что я вижу выше, - это два метода, каждый из которых может установить значение indx переменная. Что именно не работает?

David Crow

"Я устал получать доступ к indx из класса WebViewActivity..."

Но вы этого не показали.

0 Ответов