2012-06-30 3 views
0

나는 인터넷 서핑에 대한 답변을 찾으려고했지만 아무 것도 발견하지 못했습니다.누락 목록보기

여기 내 질문이 있습니다. 재미있는 자습서를 android here에서 자신의 간단한 플레이어를 개발하는 방법을 발견하고 해당 코드를 내 프로그램에 통합하기 시작했지만 Views에 문제가 있습니다. 나는 그것이 나타나는 이유조차도 이해할 수 없다 : ListView를 삽입하려고 시도했지만 아무 일도 일어나지 않았다. 그래서 여기 내 코드입니다 :

EasyFlippingActivity.java는

package my.easyflipping; 

import java.io.File; 
import java.util.ArrayList; 
import java.util.List; 

import android.app.ListActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.ViewFlipper; 

public class EasyflippingActivity extends ListActivity { 

    private ViewFlipper flipper; 
    private static final String MEDIA_PATH = new String("/sdcard/"); 
    private List<String> songs = new ArrayList<String>(); 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     this.flipper = (ViewFlipper)findViewById(R.id.flipper); 
     Button groups; 
     (groups = (Button)findViewById(R.id.groups)).setBackgroundDrawable(this.getResources().getDrawable(R.drawable.group)); 
     Button songs; 
     (songs = (Button)findViewById(R.id.songs)).setBackgroundDrawable(this.getResources().getDrawable(R.drawable.songs)); 
     groups.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       im_going_left(); 
       flipper.showNext(); 
       groups_func(); 
      } 
      }); 
     songs.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       update_song_list(); 
       im_going_right(); 
       flipper.showNext(); 
       songs_func(); 
      } 
     }); 
    } 

    public void update_song_list() { 
     File home = new File(MEDIA_PATH); 
     if (home.listFiles(new Mp3Filter()).length > 0) { 
       for (File file : home.listFiles(new Mp3Filter())) { 
         songs.add(file.getName()); 
       } 

       ArrayAdapter<String> songList = new ArrayAdapter<String>(this, 
           R.layout.song_item, songs); 
       setListAdapter(songList); 
     } 
} 


    public void songs_func() 
    { 
     Button back; 

     back = (Button)findViewById(R.id.back); 
     back.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       im_going_left(); 
       flipper.showPrevious(); 
       return; 

      } 
     }); 
    } 

    public void groups_func() 
    { 
     Button back; 

     back = (Button)findViewById(R.id.back); 
     back.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       im_going_right(); 
       flipper.showPrevious(); 
       return; 

      } 
     }); 
    } 

    public void im_going_right() 
    { 
     Animation s_in = AnimationUtils.loadAnimation(this, R.layout.slideinleft); 
     Animation s_out = AnimationUtils.loadAnimation(this, R.layout.slideoutright); 
     this.flipper.setInAnimation(s_in); 
     this.flipper.setOutAnimation(s_out); 
    } 

    public void im_going_left() 
    { 
     Animation s_in = AnimationUtils.loadAnimation(this, R.layout.slidein); 
     Animation s_out = AnimationUtils.loadAnimation(this, R.layout.slideout); 
     this.flipper.setInAnimation(s_in); 
     this.flipper.setOutAnimation(s_out); 
    } 
} 

main.xml에

<?xml version="1.0" encoding="utf-8"?> 
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/flipper" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="80dp" 
     android:src="@drawable/phones" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="400dp" > 

     <Button 
      android:id="@+id/groups" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="45dp" 
      android:text="" /> 

     <Button 
      android:id="@+id/songs" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginRight="45dp" 
      android:text="" /> 

     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/groups" 
      android:layout_below="@+id/groups" 
      android:src="@drawable/groupstext" /> 

     <ImageView 
      android:id="@+id/imageView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/imageView2" 
      android:layout_alignRight="@+id/songs" 
      android:src="@drawable/songstext" /> 
    </RelativeLayout> 

    </LinearLayout> 


    <LinearLayout android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="20dip" 
      android:layout_gravity="top" 
      android:layout_marginTop="50dip"> 
     <ListView android:id="@+id/list" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:drawSelectorOnTop="false"/> 

     <TextView android:id="@+id/empty" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:text="No songs found on SD Card."/> 
     <Button 
      android:id="@+id/back" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="45dp" 
      android:text="back" /> 


    </LinearLayout> 

</ViewFlipper> 

Mp3Filter.java

package my.easyflipping; 

import java.io.File; 
import java.io.FilenameFilter; 

public class Mp3Filter implements FilenameFilter { 

    public boolean accept(File arg0, String name) { 
     return (name.endsWith(".mp3")); 
    } 

} 

song_item.xml

<?xml version="1.0" encoding="utf-8"?> 
    <TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

그리고 오류 로그 :

06-30 18:54:56.314: D/dalvikvm(189): GC freed 735 objects/55256 bytes in 70ms 
06-30 18:54:56.354: D/AndroidRuntime(189): Shutting down VM 
06-30 18:54:56.354: W/dalvikvm(189): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 
06-30 18:54:56.354: E/AndroidRuntime(189): Uncaught handler: thread main exiting due to uncaught exception 
06-30 18:54:56.364: E/AndroidRuntime(189): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.easyflipping/my.easyflipping.EasyflippingActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.os.Handler.dispatchMessage(Handler.java:99) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.os.Looper.loop(Looper.java:123) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.ActivityThread.main(ActivityThread.java:4363) 
06-30 18:54:56.364: E/AndroidRuntime(189): at java.lang.reflect.Method.invokeNative(Native Method) 
06-30 18:54:56.364: E/AndroidRuntime(189): at java.lang.reflect.Method.invoke(Method.java:521) 
06-30 18:54:56.364: E/AndroidRuntime(189): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
06-30 18:54:56.364: E/AndroidRuntime(189): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
06-30 18:54:56.364: E/AndroidRuntime(189): at dalvik.system.NativeStart.main(Native Method) 
06-30 18:54:56.364: E/AndroidRuntime(189): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.ListActivity.onContentChanged(ListActivity.java:236) 
06-30 18:54:56.364: E/AndroidRuntime(189): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.Activity.setContentView(Activity.java:1622) 
06-30 18:54:56.364: E/AndroidRuntime(189): at my.easyflipping.EasyflippingActivity.onCreate(EasyflippingActivity.java:26) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
06-30 18:54:56.364: E/AndroidRuntime(189): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
06-30 18:54:56.364: E/AndroidRuntime(189): ... 11 more 
06-30 18:54:56.384: I/dalvikvm(189): threadid=7: reacting to signal 3 
06-30 18:54:56.384: E/dalvikvm(189): Unable to open stack trace file '/data/anr/traces.txt': Permission denied 
06-30 18:58:28.214: I/Process(189): Sending signal. PID: 189 SIG: 9 

나는 아무도 나를 도와 주면 매우 감사하게 될 것입니다. 미리 감사드립니다. 당신이 목록보기 가진 ID를 가지고 있어야합니다 activiyt 당신이 목록을 사용하는 경우

+1

당신은 ListActivity를 확장하고, 당신은 **해야 ** 아이디'과 레이아웃에있는 ListView는 @android 한 : ID를/list'. – Sam

+0

나는 그것을 가지고 있지만, 내 플리퍼의 두 번째 레이아웃에서만. 그래서 내 질문은 어떻게 시스템을 볼 수 있도록하는 것입니다. – user1493420

답변

0
Your content must have a ListView whose id attribute is 'android.R.id.list' 

는 "@android : ID/목록"

<?xml version=”1.0″ encoding=”utf-8″?> 
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” 
android:orientation=”vertical” 
android:layout_width=”fill_parent” 
android:layout_height=”fill_parent” 
> 
<TextView 
android:layout_width=”fill_parent” 
android:layout_height=”wrap_content” 
android:text=” “ 
android:id=”@+id/selection” 
/> 
<ListView 
android:id=”@android:id/list” 
android:choiceMode=”multipleChoice” 
android:layout_width=”fill_parent” 
android:layout_height=”wrap_content”/> 
</LinearLayout> 
+0

http://maohao.wordpress.com/2009/11/26/listview-and-listactivity-demo/ –

1

당신은 당신이있는 그을 필요로 ListActivity를 확장됩니다 ID가 @android:id/list 인 레이아웃의 ListView. 시도 main.xml에이 변경 :

<ListView android:id="@+id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:drawSelectorOnTop="false"/> 

이에 :

<ListView android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:drawSelectorOnTop="false"/> 
+0

+1 당신이 옳다고 생각합니다. :) –

+0

고마워요! 완료되었으며 작동했습니다. – user1493420

+0

@ user1493420 기꺼이 도와 드리겠습니다! 제 답변의 왼쪽 상단 모서리에있는 체크 표시를 클릭하여이 문제가 해결되었음을 나타냅니다. – Sam