开发者

Can't figure how to retrieve data of a particular row from a ListView

I am developing an android application pertaining to sms. I have managed to display a listView of all the messages in my android emulator, but i can't figure out what code should i write in the onItemClickListener such that whenever i click any row of my listview i should get the data(here.. message body) associated with it in another screen. What ahould i do about this?

My code is given below:

public class mainmenu extends Activity 
{


       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle SavedInstanceState) 
       {
          super.onCreate(SavedInstanceState);
          setContentView(R.layout.main);



         super.onStart();
         {

          final ListView list = (ListView) findViewById(R.id.list);
          List<String> msgList = getSMS();
          ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, msgList); 
            list.setAdapter(adapter);

            list.setOnItemClickListener(new OnItemClickListener()
            {


                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) 
                {
                   开发者_开发知识库 // TODO Auto-generated method stub

                }

            });

       }
 }






       public List<String> getSMS()
       {

           List<String> sms = new ArrayList<String>();
           Uri uriSMSURI = Uri.parse("content://sms/inbox");
          Cursor cur = getContentResolver().query(uriSMSURI, null, null,null,null);

          while (cur.moveToNext())
          {

              String address=cur.getString(cur.getColumnIndex("address"));
              String body = cur.getString(cur.getColumnIndexOrThrow("body"));
                 sms.add("Number: " + address + " .Message: " + body); 
          }
          return sms;


       }

}

Please give me the code that i should write in the OnItemClickListener as per the specifications i mentioned above. It's a bit urgent.


Just use the adapter there as such:

String itemAtClickedIntex = (String)adapter.getItem(position);

Hope this helps your urgent request :) please don't forget to accept as it encourages us to keep contributing.

Best

-serkan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜