2015-02-09 71 views
1

我的listview似乎不显示在屏幕上。Android的ListView没有出现

我正在使用一个tabhost并在框架中放置一个列表,但由于某种原因它不工作。

我敢肯定,我的代码似乎是正确的所以我不确定什么是错在这里..

请帮助!

这里是我的XML:

<?xml version="1.0" encoding="utf-8"?> 

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@android:id/tabhost"> 

    <LinearLayout 
     android:id="@+id/LinearLayout01" 
     android:orientation="vertical" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="List" 
      android:id="@+id/listtext" 
      android:layout_gravity="center_horizontal" /> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent"> 
     </TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent"> 

      <ListView 
       android:id="@+id/list" 
       android:layout_height="0dp" 
       android:layout_width="match_parent" 
       android:layout_weight="1"> 
      </ListView> 
     </FrameLayout> 
    </LinearLayout> 

</TabHost> 

标签1代码:

public class WorkoutDay1 extends Activity { 
    ListView listView ; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.workoutlist_main); 

     // Get ListView object from xml 
     listView = (ListView) findViewById(R.id.list); 
     // Defined Array values to show in ListView 
     String[] values = new String[] { "Chest Press", 
       "Shoulder Press", 
       "Arm Extension", 
     }; 

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, android.R.id.text1, values); 
     // Assign adapter to ListView 
     listView.setAdapter(adapter); 
     // ListView Item Click Listener 
     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
            int position, long id) { 

/*    // ListView Clicked item index 
       int itemPosition  = position; 

       // ListView Clicked item value 
       String itemValue = (String) listView.getItemAtPosition(position);*/ 

       // Show Alert 
       if(position == 0) { 
        //code specific to first list item 
        Intent myIntent = new Intent(view.getContext(), workout.class); 
        startActivityForResult(myIntent, 0); 

       } 

       if(position == 1) { 
        //code specific to 2nd list item 
        Toast.makeText(getApplicationContext(), 
          "Coming Soon.", Toast.LENGTH_SHORT) 
          .show(); 
       } 

       if(position == 2) { 
        //code specific to 2nd list item 
        Toast.makeText(getApplicationContext(), 
          "Coming Soon." , Toast.LENGTH_SHORT) 
          .show(); 
       } 

      } 

     }); 




    } 

} 

回答

0

您hvnt贴出你的完整代码,但我只是猜测,你可能没有叫notifyDataSetChanged()到列表分配数据之后..

+0

我更新了我的代码,不太确定放哪里说你说的。 – Bimal 2015-02-09 21:56:48

+0

在行后添加它listView.setAdapter(adapter); – 2015-02-10 04:12:45

+0

它说不能解决方法。 – Bimal 2015-02-10 11:30:56