0

I have a on strings.xml file. All the entries are showen a on ListView, and now i want to make a treatement on evey item touch/click. I have righted this code:

> public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>        
>         
>         setListAdapter(ArrayAdapter.createFromResource(getApplicationContext(),
>                 R.array.tut_titles, R.layout.offresaffichage));
>         
>     }
>     
>         public void onItemClick(AdapterView<?> parent, View view,
>                 int position, long id) {
>           final String[] links = getResources().getStringArray(R.array.tut_titles);
// what to do here?

How to retrieve item position on the and start another activity from it? I thinked about switch, case but don't know how implement it. Thanks for answering.

1 Answer 1

2

You can use the second int of your parameter list in the onItemClick method :

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   final String[] links = getResources().getStringArray(R.array.tut_titles);
   String link = links[ position ];
   Intent i = new Intent(Intent.ACTION_VIEW);  
   i.setData(Uri.parse( link ));  
   startActivity(i);          
}//met
8
  • In that case, how it will know that this onitemClick is for the <string-array> ? this code is "independent". ? Commented Feb 25, 2012 at 13:00
  • I have some strings in the string.xml file as <string-array>, i have adapted this strings on a listview and they are well showen, in cons, i don't know how to manipulate that strings, when i tap on one of them i have a triggered intent. Hope that this is more clear now :) Commented Feb 25, 2012 at 13:05
  • nope. Sorry. But I believe you have everything you need. you don't have to care about what's in the string at which row, just wonder how to react whedn this or that row is clicked. Commented Feb 25, 2012 at 13:07
  • Exactly, don't know how to react when an item on <srting-array> is clicked. Anyway, i'll return to listview+ arraylist. Wanted to have things more simple and more clear :/. Commented Feb 25, 2012 at 13:10
  • 1
    you should put that code into an inner class that implements OnItemClickListener, then instanciate this inner class and register it on the list view using lv.setOnItemClickListener( new <your inner class>); Commented Feb 25, 2012 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.