0

I am using the following code shows me the position of a text within a listview. I want to display a text or string if i write the number of position in a textedit.

In short... If i write the position number of the item from the listview it will give me the result of the text or string in that certain position.

public void onClick(View v){

    try {
        View parentRow = (View) v.getParent();
        list = (ListView) parentRow.getParent();
        final int position = lista.getPositionForView(parentRow);
        Toast.makeText(getBaseContext(),"The "+position, Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        e.printStackTrace();

    }
}
Jeremy W
  • 1,751
  • 6
  • 25
  • 33

1 Answers1

0

So it is something like this (pseudo):

    final EditText edittext = (EditText) findViewById(...);
    Button button = (Button) findViewById(...);
    final ListView listview = (ListView) findViewById(...);
    listview.setAdapter(...) // remember to set an adapter to listview
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = Integer.parseInt(edittext.getText().toString()); // make sure to have an numeric edittext
            Object obj = listview.getAdapter().getItem(position); // this is your object, string, text (whatever)
        }
    });
  • I'm sorry, but this does not work in my case. I've tried this method before, but this code returns an object value that is not on my list. I guess its because my adapter list returns a value of JSON. Thanks :/ – Daniel Navarro May 06 '16 at 16:26