2013-02-22 2 views
0

ListView를 작동 시키려고하는데 응용 프로그램을 닫아야하는 화면에 메시지가 표시됩니다! 오류를 찾고 있는데 아무 것도 찾을 수 없습니다! 레이아웃 안에있는 것일까 요? ListView를 거기에 넣어야하는지, 아니면 이것이 CDynamic으로 작성해야하는지 잘 모르겠다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 또한 onClick 메서드를 사용할 것입니다.하지만이 경우에는 광부 문제가있는 것 같습니다. 일부 도움을 preciate! 감사!ListView 강제 종료 응용 프로그램

public class Activity_3 extends ListActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    String[] projection = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID}; 

    // Get a cursor with all people 
    Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI, 
      projection, null, null, null); 

    startManagingCursor(cursor); 

    ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.activity_3, cursor, new String[] {ContactsContract.Contacts.DISPLAY_NAME}, new int[] {R.id.contactItem }); 

    setListAdapter(adapter); 
} 
} 

레이아웃

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ListView 
    android:id="@+id/contactList" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 

<TextView android:id="@+id/contactItem" > 
</TextView> 

</LinearLayout> 
+2

DDMS 오류 로그를 게시 해주십시오. logcat 창을 열고 앱 필터를 추가하십시오. 그런 다음 오류를 볼 수 있습니다. 또한 레이아웃 XML이 불완전한 것 같습니다. 어떤 IDE를 사용하고 있습니까? – Timmetje

+0

SimpleCursorAdapter 또는 baseadapter를 확장하는 ur adapterclass는 어디입니까? – saran

+0

List Activity를 확장하는 경우 레이아웃에 listview를 넣지 않아도됩니다. – Anukool

답변

1

당신은

확인 지금이

public class mainact extends Activity { 

    ListView l; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.abc); 
     l=(ListView)findViewById(R.id.contactList); 

     String[] projection = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID}; 

     // Get a cursor with all people 

     Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,null,null, null); 

     while (phones.moveToNext()) 
     { 
      String Name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); 
      String Number=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 

     } 
     startManagingCursor(phones); 

     ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.abc, phones, new String[] {ContactsContract.Contacts.DISPLAY_NAME}, new int[] {R.id.contactItem }); 

     l.setAdapter(adapter); 
    } 
    } 

활동해야하며, XML이어야 manifest.xml에이 권한

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission> 

을 추가 한

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ListView 
    android:id="@+id/contactList" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 

<TextView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/contactItem" > 
</TextView> 

</LinearLayout> 
같은

또는 필요한 것만 적합하지만 작동 코드입니다

+0

예! 그것은 이미 완료되었습니다! –

+0

그래서 오류 로그를 게시해야하는 이유가 무엇인지, 우리는 그 오류의 원인을 알지 못합니다. 그것은 무엇이든 수 있습니다. – Timmetje

+0

도움을 주셔서 감사합니다! –

0

난 당신이 각 뷰는 다른 ListView에 포함되어 뷰를 생성 어댑터를 사용하려고 알고있는 것처럼?

<ListView 
    android:id="@+id/contactList" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 

는 일반적으로 다른있는 ListView에있는 ListView를 넣을 수 없습니다 삭제합니다.

+0

아니오 나는 그렇게 생각하지 않는다 :) 나는 모든 연락처 이름의 목록을 얻고 이름과 전화 번호를 선택할 수있게하고 싶다. –

관련 문제