我正在开发一个与短信有关的android应用程序。我已经设法在我的android模拟器中显示所有消息的listView,但我无法弄清楚我应该在onItemClickListener中编写什么代码,这样每当我点击listview的任何行时我都应该获取数据(这里..消息体)与另一个屏幕相关联。我该怎么办?
我的代码如下:
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;
}
}
请根据我上面提到的规范,给我在OnItemClickListener中编写的代码。这有点紧急。
答案 0 :(得分:0)
只需在那里使用适配器:
String itemAtClickedIntex = (String)adapter.getItem(position);
希望这有助于您的紧急要求:)请不要忘记接受,因为它鼓励我们继续做出贡献。
最佳
-serkan