我的列表视图似乎无法在屏幕上显示。
我正在使用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 :(得分:0)
您发布了完整的代码,但我猜您在将数据分配到列表后可能没有调用notifyDataSetChanged()
。