这是我的第二个应用,也是第一个使用 ListActivity。某处的播放效果不佳 - 活动 (ShowWidget) 显示 - 但列表为空。
这是我的 ListActivity 代码:
import android.app.ListActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ShowWidget extends ListActivity {
DataProvider db = new DataProvider(ShowWidget.this);
public static String sound;
MediaPlayer mp = new MediaPlayer();
@SuppressWarnings("unused")
private ListView LV;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Toast.makeText(getApplicationContext(), "Loading your settings.", Toast.LENGTH_SHORT).show();
LV = (ListView)findViewById(android.R.id.list);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS));
getListView().setTextFilterEnabled(true);
// change to our configure view
setContentView(R.layout.widget_show);
/*db.open();
Cursor cursor = db.getRecord(1);
ShowWidget.sound = cursor.getString(cursor.getColumnIndex("sound"));
cursor.close();
db.close();*/
}
static final String[] PENS = new String[]{
"MONT Blanc", "Gucci", "Parker", "Sailor",
"Porsche Design", "Rotring", "Sheaffer", "Waterman"
};
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String pen = o.toString();
Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();
}
public void play(){
}
}
和我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/widgetShow">
<ListView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@android:id/list"
android:layout_weight="1">
</ListView>
</LinearLayout>
就像我说的,我在这里做错了 - 活动显示,但不是存储在 PENS 中的数据。任何朝着正确方向的想法或观点将不胜感激!如果问题不清楚,请发表评论,我会编辑问题以使其更清楚。