2013-03-20 58 views
4

如何將列表視圖放入片段?我使用固定選項卡的默認項目設置。如何把listview放入片段

它似乎不工作,我的應用程序崩潰。

主要活動

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.Locale; 

import org.w3c.dom.Document; 
import org.w3c.dom.Element; 
import org.w3c.dom.NodeList; 

import android.app.ActionBar; 
import android.app.FragmentTransaction; 
import android.app.ListActivity; 
import android.app.ListFragment; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
import android.os.StrictMode; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentPagerAdapter; 
import android.support.v4.view.ViewPager; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ListAdapter; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
import android.widget.Toast; 

public class MainActivity extends FragmentActivity implements 
     ActionBar.TabListener { 
    /** 
    * The {@link android.support.v4.view.PagerAdapter} that will provide 
    * fragments for each of the sections. We use a 
    * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which 
    * will keep every loaded fragment in memory. If this becomes too memory 
    * intensive, it may be best to switch to a 
    * {@link android.support.v4.app.FragmentStatePagerAdapter}. 
    */ 

    /** 
    * The {@link ViewPager} that will host the section contents. 
    */ 
    ViewPager mViewPager; 
    public final static String PREFS_NAME = "UserData"; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     //Only for safe mode 
     StrictMode.ThreadPolicy policy = new StrictMode. 
     ThreadPolicy.Builder().permitAll().build(); 
     StrictMode.setThreadPolicy(policy); 
     /***********************************USER***************************/ 
     //Get User info (if exist) 
     SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
     String id = settings.getString("id", ""); 
     String pass = settings.getString("pass", ""); 
     SectionsPagerAdapter mSectionsPagerAdapter; 
     //Else create New User 
     if (id == "") 
     { 
      System.out.println("Create New User..."); 
      UserRegistration.CreateUser(getApplicationContext()); 
     } 
     /**** OTHER*****/ 
     super.onCreate(savedInstanceState); 


     setContentView(R.layout.activity_main); 
     // Set up the action bar. 
     final ActionBar actionBar = getActionBar(); 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
     // Create the adapter that will return a fragment for each of the three 
     // primary sections of the app. 
     mSectionsPagerAdapter = new SectionsPagerAdapter(
       getSupportFragmentManager()); 

     // Set up the ViewPager with the sections adapter. 
     mViewPager = (ViewPager) findViewById(R.id.pager); 
     mViewPager.setAdapter(mSectionsPagerAdapter); 
     // When swiping between different sections, select the corresponding 
     // tab. We can also use ActionBar.Tab#select() to do this if we have 
     // a reference to the Tab. 
     mViewPager 
       .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 
        @Override 
        public void onPageSelected(int position) { 
         actionBar.setSelectedNavigationItem(position); 
        } 
       }); 

     // For each of the sections in the app, add a tab to the action bar. 
     for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { 
      // Create a tab with text corresponding to the page title defined by 
      // the adapter. Also specify this Activity object, which implements 
      // the TabListener interface, as the callback (listener) for when 
      // this tab is selected. 
      actionBar.addTab(actionBar.newTab() 
        .setText(mSectionsPagerAdapter.getPageTitle(i)) 
        .setTabListener(this)); 
     } 


    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public void onTabSelected(ActionBar.Tab tab, 
      FragmentTransaction fragmentTransaction) { 
     // When the given tab is selected, switch to the corresponding page in 
     // the ViewPager. 
     mViewPager.setCurrentItem(tab.getPosition()); 
    } 

    @Override 
    public void onTabUnselected(ActionBar.Tab tab, 
      FragmentTransaction fragmentTransaction) { 
    } 

    @Override 
    public void onTabReselected(ActionBar.Tab tab, 
      FragmentTransaction fragmentTransaction) { 
    } 

    /** 
    * A {@link FragmentPagerAdapter} that returns a fragment corresponding to 
    * one of the sections/tabs/pages. 
    */ 
    public class SectionsPagerAdapter extends FragmentPagerAdapter { 

     public SectionsPagerAdapter(FragmentManager fm) { 
      super(fm); 
     } 

     @Override 
     public Fragment getItem(int position) { 
      // getItem is called to instantiate the fragment for the given page. 
      // Return a DummySectionFragment (defined as a static inner class 
      // below) with the page number as its lone argument. 
      Fragment fragment = new DummySectionFragment(); 
      Bundle args = new Bundle(); 
      args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1); 
      fragment.setArguments(args); 
      return fragment; 
     } 

     @Override 
     public int getCount() { 
      // Show 5 total pages. 
      return 5; 
     } 

     @Override 
     public CharSequence getPageTitle(int position) { 
      Locale l = Locale.getDefault(); 
      switch (position) { 
      case 0: 
       return getString(R.string.title_section1).toUpperCase(l); 
      case 1: 
       return getString(R.string.title_section2).toUpperCase(l); 
      case 2: 
       return getString(R.string.title_section3).toUpperCase(l); 
      case 3: 
       return getString(R.string.title_section4).toUpperCase(l); 
      case 4: 
       return getString(R.string.title_section5).toUpperCase(l); 
      } 
      return null; 
     } 
    } 

    /** 
    * A dummy fragment representing a section of the app, but that simply 
    * displays dummy text. 
    */ 
    public static class DummySectionFragment extends Fragment { 
     /** 
     * The fragment argument representing the section number for this 
     * fragment. 
     */ 
     public static final String ARG_SECTION_NUMBER = "section_number"; 

     public DummySectionFragment() { 
     } 

     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 


      View rootView = inflater.inflate(R.layout.fragment_main_dummy, container, false);  
      /***********************************CONTEST INC********************** 
      String xmlURL; 
      ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); 
      xmlURL = URL; 
      System.out.println("Case 1"); 
      Document doc = XMLfunctions.XMLfromString(XMLfunctions.getXML(xmlURL)); 
      NodeList nodes = doc.getElementsByTagName("contest"); 
      for (int i = 0; i < nodes.getLength(); i++) 
      {       
       HashMap<String, String> map = new HashMap<String, String>();  

       Element e = (Element)nodes.item(i); 
       map.put("id", XMLfunctions.getValue(e, "id")); 
       map.put("name", XMLfunctions.getValue(e, "name")); 
       map.put("subtitle",XMLfunctions.getValue(e, "subtitle")); 
       mylist.add(map); 
       System.out.println(mylist); 
      } 
      //new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, android.R.id.text1, actions); 

      ListAdapter adapter = new SimpleAdapter(this.getActivity(), mylist , R.layout.contest_list, 
        new String[] { "name", "subtitle" }, 
        new int[] { R.id.item_title, R.id.item_subtitle }); 

      ListFragment.setListAdapter(adapter); 

      final ListView lv = getApplication().getActivity().getListView(); 
      lv.setTextFilterEnabled(true); 
      lv.setOnItemClickListener(new OnItemClickListener() { 
       public void onItemClick(AdapterView<?> parent, View view, int position, long id) {    
        @SuppressWarnings("unchecked") 
        HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);     
        Toast.makeText(this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_LONG).show(); 

       } 
      }); 



      /*************************************END CONTEST*********************/ 
      ContestList.GetList(getActivity(), 1, "mm", "njk"); 

      //TextView dummyTextView = (TextView) rootView 
       // .findViewById(R.id.section_label); 
      String sectionNumb = Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)); 
      int cat1; 
      cat1 = Integer.parseInt(sectionNumb); 
      switch (cat1) 
      { 
      case 1: 
       break; 
      case 2: 
       break; 
      case 3: 
       break; 
      case 4: 
       break; 
      case 5: 
       break; 
      } 
      return rootView; 
     } 
    } 
} 

ContestList類

import java.util.ArrayList; 
import java.util.HashMap; 

import org.w3c.dom.Document; 
import org.w3c.dom.Element; 
import org.w3c.dom.NodeList; 

import android.app.ListActivity; 
import android.app.ListFragment; 
import android.content.Context; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ListAdapter; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
import android.widget.Toast; 

public class ContestList { 
    public final static String PREFS_NAME = "UserData"; 

    public static String GetList(Context context, int type, String id, String pass) 
    { 

     String xmlURL; 
     ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); 
     xmlURL = URL; 
     System.out.println("Case 1"); 
     Document doc = XMLfunctions.XMLfromString(XMLfunctions.getXML(xmlURL)); 
     NodeList nodes = doc.getElementsByTagName("contest"); 
     for (int i = 0; i < nodes.getLength(); i++) 
     {       
      HashMap<String, String> map = new HashMap<String, String>();  

      Element e = (Element)nodes.item(i); 
      map.put("id", XMLfunctions.getValue(e, "id")); 
      map.put("name", XMLfunctions.getValue(e, "name")); 
      map.put("subtitle",XMLfunctions.getValue(e, "subtitle")); 
      mylist.add(map); 
      System.out.println(mylist); 
     } 
     //new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, android.R.id.text1, actions); 

     ListAdapter adapter = new SimpleAdapter(context, mylist , R.layout.contest_list, 
       new String[] { "name", "subtitle" }, 
       new int[] { R.id.item_title, R.id.item_subtitle }); 

     ((ListActivity) context).setListAdapter(adapter); 

     final ListView lv = ((ListActivity) context).getListView(); 
     lv.setTextFilterEnabled(true); 
     lv.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {    
       @SuppressWarnings("unchecked") 
       HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);     
       //Toast.makeText(Main.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_LONG).show(); 

      } 
     }); 
     return "OK"; 
    } 
    public String adapter(ListAdapter adapter) 
    {/* 
     setListAdapter(adapter); 

     final ListView lv = getApplication().getActivity().getListView(); 
     lv.setTextFilterEnabled(true); 
     lv.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {    
       @SuppressWarnings("unchecked") 
       HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);     
       Toast.makeText(MainActivity.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_LONG).show(); 

      } 
     });*/ 
     return "OK"; 
    } 
} 

activity_main佈局:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" /> 

Fragment_main_dummy佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent">  

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

<TextView 
    android:id="@id/android:empty" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="No data"/> 

<TextView 
android:id="@+id/item_title" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textAppearance="?android:attr/textAppearanceMedium" 
android:padding="2dp" 
android:textSize="20dp" /> 
<TextView 
android:id="@+id/item_subtitle" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:padding="2dp" 
android:textSize="13dp" /> 

有人知道爲什麼我的應用程序崩潰?或者有一個替代方案,把一個listview內的片段?

感謝

編輯:

錯誤日誌

03-20 12:53:31.219: E/AndroidRuntime(3104): FATAL EXCEPTION: main 
03-20 12:53:31.219: E/AndroidRuntime(3104): java.lang.ClassCastException: com.time2win.MainActivity cannot be cast to android.app.ListActivity 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at com.time2win.ContestList.GetList(ContestList.java:50) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at com.time2win.MainActivity$DummySectionFragment.onCreateView(MainActivity.java:241) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.view.ViewPager.populate(ViewPager.java:1012) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.view.ViewPager.populate(ViewPager.java:881) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.View.measure(View.java:15513) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.View.measure(View.java:15513) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:847) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.View.measure(View.java:15513) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.View.measure(View.java:15513) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.Choreographer.doCallbacks(Choreographer.java:562) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.Choreographer.doFrame(Choreographer.java:532) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.os.Handler.handleCallback(Handler.java:725) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.os.Handler.dispatchMessage(Handler.java:92) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.os.Looper.loop(Looper.java:137) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at android.app.ActivityThread.main(ActivityThread.java:5039) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at java.lang.reflect.Method.invoke(Method.java:511) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
03-20 12:53:31.219: E/AndroidRuntime(3104):  at dalvik.system.NativeStart.main(Native Method) 
+0

你能後的堆棧跟蹤崩潰? – hyarion 2013-03-20 13:03:04

+0

我只是添加日誌 – 2013-03-20 13:11:15

回答

0

你所得到的錯誤是由於試圖設置主要活動的listadapter代替的名單。

在您的比賽名單類,你做到以下幾點:

((ListActivity) context).setListAdapter(adapter); 

但上下文不是ListActivity,它是MainActivity。

你這樣做:

ContestList.GetList(getActivity(), 1, "mm", "njk"); 

但getActivity()意味着它返回的主要活動是 「MainActivity」。你應該改變事情來通過列表視圖而不是活動上下文,或者找到另一種方式來傳遞你需要的數據。

7

我得到了輸出!

public class TopRatedFragment extends Fragment { 

private String[] mNames = { "Fabian", "Carlos", "Alex", "Andrea", "Karla", 
     "Freddy", "Lazaro", "Hector", "Carolina", "Edwin", "Jhon", 
     "Edelmira", "Andres" }; 

private String[] mAnimals = { "Perro", "Gato", "Oveja", "Elefante", "Pez", 
     "Nicuro", "Bocachico", "Chucha", "Curie", "Raton", "Aguila", 
     "Leon", "Jirafa" }; 

int[] flags = new int[]{ 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher, 
     R.drawable.ic_launcher 
}; 


    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 

List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>(); 

for(int i=0;i<10;i++){ 
    HashMap<String, String> hm = new HashMap<String,String>(); 
    hm.put("txt", "App Name : " + mNames[i]); 
    hm.put("cur","creator : " + mAnimals[i]); 
    hm.put("flag", Integer.toString(flags[i])); 
    aList.add(hm);   
} 
String[] from = { "flag","txt","cur" }; 

int[] to = { R.id.flag,R.id.txt,R.id.cur,R.id.textView2}; 

View v = inflater.inflate(R.layout.fragment_top_rated, container,false); 
    ListView list = (ListView)v.findViewById(R.id.listView1); 
SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.listview_layout, from, to);  
    list.setAdapter(adapter); 
return v; 
} 
} 

listview_layout.xml

<?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="horizontal"> 

<ImageView 
     android:id="@+id/flag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/hello_world" 
     android:paddingTop="10dp" 
     android:paddingRight="10dp" 
     android:paddingBottom="10dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" >  

     <TextView 
      android:id="@+id/txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="15dp" />   

     <TextView 
      android:id="@+id/cur" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="10dp" /> 

</LinearLayout> 

</LinearLayout> 

fragment_top_rated.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" > 
</ListView> 

</RelativeLayout> 
3

包含與3個元素的列表視圖中的片段的一個例子。關鍵是onCreateView,不要忘記膨脹fragment.xml之(fragment_list),這一個範圍內會出現與「ListView控件$ fragment_list $ LISTA」的在ListView

public class FragmentList extends Fragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,BundlesavedInstanceState) { 

    View v = inflater.inflate(R.layout.fragment_list, container, false); 

    ListView lstItems = (ListView)v.findViewById(R.id.listView$fragment_list$lista); 

    ArrayList<String> prueba = new ArrayList<String>(); 
    prueba.add("Element1"); 
    prueba.add("Element2"); 
    prueba.add("Element3"); 

    ArrayAdapter<String> allItemsAdapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_1,prueba); 

    lstItems.setAdapter(allItemsAdapter); 

    return v; 
}