i created a layout containing multiple text views. i saved the text view's ids in an ArrayList which is a class variable called _resultId.
now i want to create buttons which suppose to scroll to the correct text view (the first button to the first text view etc)
the question is: how to pass the correct id to each of the buttons on press method?
i tried using a global variable _counter but when i run the program all the buttons scroll to the last text view
the code of the method:
private void addNavigationView(ViewGroup navigationLayout, ArrayList<Perek> mishnayot)
{
for (int i=0;i<mishnayot.size();i++)
{
_counter=i;
String currentOt=mishnayot.get(i).getOt();
Button button = new Button(getBaseContext());
button.setText(currentOt);
if (_resultId==null)
throw new IllegalAccessError("missing result id link cannot be created");
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) //make it scroll to correct textview
{
new Handler().post(new Runnable()
{
@Override
public void run()
{
View currentView=findViewById(_resultId.get(_counter));
ScrollView scrollView=(ScrollView) findViewById(R.id.resultScroll);
scrollView.scrollTo(0, currentView.getTop());
}
});
}
});
navigationLayout.addView(button);//add the button to panel
}
navigationLayout.setVisibility(View.VISIBLE);
}