2010-09-28 7 views
0

J'essaye de faire la vue de liste mais j'obtiens l'erreur de suite n'importe qui peut me dire le mauvais quoi avec mon code.ListView en utilisant Layout Infleter dans android

alors s'il vous plaît aidez-moi.

09-28 10: 52: 28,918: ERREUR/AndroidRuntime (383): Causé par: java.lang.RuntimeException: Votre contenu doit avoir un ListView dont l'attribut id est 'android.R.id.list' 09 -28 10: 52: 28.918: ERROR/AndroidRuntime (383): at android.app.ListActivity.onContentChanged (ListActivity.java:245) 09-28 10: 52: 28.918: ERROR/AndroidRuntime (383): à com. android.internal.policy.impl.PhoneWindow.setContentView (PhoneWindow.java:201) 09-28 10: 52: 28.918: ERROR/AndroidRuntime (383): à l'adresse android.app.Activity.setContentView (Activity.java:1647) 09-28 10: 52: 28.918: ERROR/AndroidRuntime (383): à com.unundoinc.FaceBook.Activity.NewsFeedActivity.onCreate (NewsFeedActivity.java:51) 09-28 10: 52: 28.918: ERROR/AndroidRuntime (383): chez android.app.In strumentation.callActivityOnCreate (Instrumentation.java:1047) oct 9 à 28: 52: 28,918: ERREUR/AndroidRuntime (383): à android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2627)

* * * **CECI EST MON DOSSIER XML QUI CONTIENT LISTE VOIR ** * ** * *

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

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

</LinearLayout> 

** * ** * ***CECI EST MON DOSSIER .JAVA ** * ** * ** * ** * ** *

public class NewsFeedActivity extends ListActivity 
{ 
    public ArrayList<UserDetail> mData ; 
    private ListView feedbookListView; 


    OAuth oauth = new OAuth(); 
    public static final String TAG = "NewsFeedActivity"; 
    public static final String FaceBookURL = "http://graph.facebook.com/"; 

    private ListAdapter objListAdapter; 

    private TextView textMessage = null; 
    private ImageView backThumbnail = null; 
    private ImageView urlThumbnail = null; 

    private String access_token = ""; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstance) 
    { 
     super.onCreate(savedInstance); 
     access_token = getIntent().getExtras().getString("ACCESS_TOKEN"); 
     setContentView(R.layout.newsfeedactivity); 

     // Setting Context of the ThumbnailManager 
     ThumbnailManager.context = this; 

     feedbookListView = (ListView) findViewById(R.id.list); 
     textMessage = (TextView)findViewById(R.id.facebook_text); 


     mData = new ArrayList<UserDetail>(); 
     this.objListAdapter = new ListAdapter(this, R.layout.newsfeedactivitycell, mData); 
     setListAdapter(objListAdapter); 

     onComplete(); 

    } 
    ////////////////////////////////////////////////////////////////////////////// 
    public void onComplete() 
    {  
     Bundle parameters = new Bundle(); 
     String response = null; 

     /*Inserts a String value into the mapping of this Bundle, 
      replacing any existing value for the given key. Either key or value may be null. 
     */ 
     parameters.putString("access_token", access_token); 
     //parameters.putString("method", "platform/posts"); 

     Log.v(TAG, "PARAMETERS :: "+parameters); 
     try 
     { 
      response = oauth.request("platform/posts" , parameters); 
      android.util.Log.v(TAG, "RESPONSE :: " + response); 
     } 
     catch (MalformedURLException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     catch (IOException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     /** 
     * To parse the FeedBook using JSON parsing 
     */ 


     try 
     { 
      JSONObject temp = new JSONObject(response); 
      JSONArray arrayOfJsonObjs = temp.getJSONArray("data"); 
      Log.v(TAG, "ARRAY SIZE :: " + arrayOfJsonObjs.length()); 
      UserDetail objUserDetail = new UserDetail(); 
      for(int i = 0; i< arrayOfJsonObjs.length(); i++) 
      { 
       try 
       { 
        JSONObject objFromArr = arrayOfJsonObjs.getJSONObject(i); 
        JSONObject objFromObj = objFromArr.getJSONObject("from"); 

        if(objFromObj.has("id") == true) 
        { 
         objUserDetail.setUserId(objFromObj.getString("id")); 
        } 
        else 
        { 
         objUserDetail.setUserId(""); 
        } 

        if(objFromObj.has("name") == true) 
        { 
         objUserDetail.setUserName(objFromObj.getString("name")); 
        } 
        else 
        { 
         objUserDetail.setUserName(""); 
        } 

        if(objFromArr.has("picture") == true) 
        { 
         objUserDetail.setUserStatusImage(objFromArr.getString("picture")); 
        } 
        else 
        { 
         objUserDetail.setUserStatusImage(""); 
        } 

        if(objFromArr.has("caption") == true) 
        { 
         objUserDetail.setUserStatus(objFromArr.getString("caption")); 
        } 
        else 
        { 
         objUserDetail.setUserStatus(""); 
        } 

        objUserDetail.setUserProfileImageUrl 
        (FaceBookURL+ 
          objUserDetail.getUserId()+ 
          "/picture" 
        ); 

        Log.v 
        (
          TAG, 
          //" Array Of Json Objects : [" + i+"] is::" + arrayOfJsonObjs.getJSONObject(i) 
          //"ICON URL ["+i+"] is ::"+objFromArr.getString("icon") 
          "OBJECT ["+i+"]"+ "\n"+ 
          "Picture URL is ::"+objUserDetail.getUserStatusImage() + "\n"+ 
          "This is your id :: "+objUserDetail.getUserId()+ "\n"+ 
          "This is your name ::"+objUserDetail.getUserName()+ "\n"+ 
          "This is Status Message ::"+objUserDetail.getUserStatus()+ "\n"+ 
          "Profile picture image URL is ::"+objUserDetail.getUserProfileImageUrl() 

        ); 
       } 
       catch (JSONException e) 
       { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     } 

     catch (JSONException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

    } 

    //////////////////////////////////////////////////////////////////////////// 

    public class ListAdapter extends ArrayAdapter<UserDetail> 
    { 
     LayoutInflater inflater; 
     private ThumbnailManager objThumbnailManager = new ThumbnailManager(); 
     private ArrayList<UserDetail> items; 

     //private Bitmap back = null; 
     //private Bitmap type = null; 


     public ListAdapter(Activity context, int textViewResourceId,ArrayList<UserDetail> items) 
     { 
      super(context, textViewResourceId, items); 
      this.items = items; 
     } 



     @Override 
     public View getView(int position, View convertView, ViewGroup parent) 
     {   
      //View row = inflater.inflate(R.layout.newsfeedactivitycell, null); 
      View objView= convertView; 
      if (objView == null) 
      { 
       LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       objView = vi.inflate(R.layout.newsfeedactivitycell, null); 
      } 

      UserDetail objUserDetail = items.get(position); 
      if (objUserDetail != null) 
      { 

       textMessage = (TextView)findViewById(R.id.facebook_text); 

       if(textMessage != null) 
       { 
        textMessage.setText("StatusMessage: "+ objUserDetail.getUserStatus()); 
       } 
      } 

      return objView; 

      //   textMessage = (TextView) row.findViewById(R.id.facebook_text); //id    
      //   //backThumbnail = (ImageView) row.findViewById(R.id.facebook_thumbnail); //drawable 
      //   textMessage.setText(objListAdapter.getItem(position).getUserStatus());   



     }  

    } 
} 

Répondre

2

Modifier id de votre liste à android:id="@android:id/list" et il devrait empêcher l'exception que vous avez