我正在构建SD卡中所有视频的列表视图,但在启动此Activity
时,应用程序没有响应。控制台中也没有关于运行时异常的消息。
public class VideoList extends Activity {
ListView listView;
LinearLayout nov;
String lan;
String videoList[];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView = (ListView) findViewById(android.R.id.list);
lan = getIntent().getExtras().getString("lang");
nov = (LinearLayout) findViewById(R.id.nov);
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaStore.Video.VideoColumns.DISPLAY_NAME };
Cursor c = getContentResolver()
.query(uri, projection, null, null, null);
if (c == null)
nov.setVisibility(View.VISIBLE);
int i = 0;
videoList = new String[c.getCount()];
while (c.moveToNext()) {
videoList[i++] = c.getString(0);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,
videoList);
setContentView(R.layout.videolist);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Intent i = new Intent(VideoList.this, Subactivity.class);
i.putExtra("lang", lan);
i.putExtra("name", arg0.getItemAtPosition(arg2).toString());
startActivity(i);
}
});
}
}
这是videolist.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/nov"
android:visibility="gone"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fontFamily="san serif"
android:gravity="center"
android:paddingTop="100dp"
android:text="No videos found"
android:textSize="16sp" />
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:fontFamily="san serif"
></ListView>
</LinearLayout>
答案 0 :(得分:4)
试试这个..
在初始化setContentView
和ListView
LinearLayout
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videolist);
修改强>
if (c == null || c.getCount() <= 0)
nov.setVisibility(View.VISIBLE);