2012-01-10 3 views
0

어떻게 할 수 있습니까? 나는 여러 가지 방법을 시도한다. 그러나 나는 기울인다. 내가 한 일은 메시지로 목록을 채우는 것입니다. 하지만 그걸 만지면 아무것도하지 않습니다. 목록을 클릭 할 수있게 만들고 메시지를 가져 오는 방법은 무엇입니까?listview에서 메시지를 가져 와서 edittext로 인쇄하십시오.

여기 내 코드가 목록에 나와 있습니다. 받은 편지함을 읽습니다.

ListView lViewSMS = (ListView) findViewById(R.id.listViewSMS); 


    if(fetchInbox()!=null) 
    { 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fetchInbox()); 
     lViewSMS.setAdapter(adapter); 
    } 
} 

public ArrayList<String> fetchInbox() { 
    ArrayList<String> sms = new ArrayList<String>(); 

    Uri uriSms = Uri.parse("content://sms/inbox"); 
    Cursor cursor = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"},null,null,null); 

    cursor.moveToFirst(); 
    while (cursor.moveToNext()) 
    { 
      String address = cursor.getString(1); 
      String body = cursor.getString(3); 

      System.out.println("======> Mobile number => "+address); 
      System.out.println("=====> SMS Text => "+body); 

      sms.add(address+"\n"+body); 

    } 

    return sms; 


} 

내 코드에 무엇을 추가 할 수 있습니까?

답변

0

lViewSMS 용 OnItemClick Listener를 작성해야합니다. 여기

lViewSMS .setOnItemClickListener(new OnItemClickListener() { 
    public void onItemClick(AdapterView<?> parent, View view, 
     int position, long id) { 
     // When clicked, show a toast with the TextView text 
     Toast.makeText(getApplicationContext(), ((TextView) view).getText(), 
      Toast.LENGTH_SHORT).show(); 
    } 
    }); 

안드로이드 링크 ListView

에게 있습니다