Android 缺少ListView
我一直在网上寻找答案,但什么也没找到 所以我的问题是:我发现了一个有趣的教程,介绍了如何在android上开发自己的简单播放器,并开始将这些代码集成到我的程序中,但在视图方面遇到了问题。我甚至不明白为什么会出现这种情况:我尝试过在任何地方插入ListView,但什么也没发生。这是我的代码: EasyLippingActivity.javaAndroid 缺少ListView,android,xml,listview,Android,Xml,Listview,我一直在网上寻找答案,但什么也没找到 所以我的问题是:我发现了一个有趣的教程,介绍了如何在android上开发自己的简单播放器,并开始将这些代码集成到我的程序中,但在视图方面遇到了问题。我甚至不明白为什么会出现这种情况:我尝试过在任何地方插入ListView,但什么也没发生。这是我的代码: EasyLippingActivity.java package my.easyflipping; import java.io.File; import java.util.ArrayList; impo
package my.easyflipping;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ViewFlipper;
public class EasyflippingActivity extends ListActivity {
private ViewFlipper flipper;
private static final String MEDIA_PATH = new String("/sdcard/");
private List<String> songs = new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.flipper = (ViewFlipper)findViewById(R.id.flipper);
Button groups;
(groups = (Button)findViewById(R.id.groups)).setBackgroundDrawable(this.getResources().getDrawable(R.drawable.group));
Button songs;
(songs = (Button)findViewById(R.id.songs)).setBackgroundDrawable(this.getResources().getDrawable(R.drawable.songs));
groups.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
im_going_left();
flipper.showNext();
groups_func();
}
});
songs.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
update_song_list();
im_going_right();
flipper.showNext();
songs_func();
}
});
}
public void update_song_list() {
File home = new File(MEDIA_PATH);
if (home.listFiles(new Mp3Filter()).length > 0) {
for (File file : home.listFiles(new Mp3Filter())) {
songs.add(file.getName());
}
ArrayAdapter<String> songList = new ArrayAdapter<String>(this,
R.layout.song_item, songs);
setListAdapter(songList);
}
}
public void songs_func ()
{
Button back;
back = (Button)findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
im_going_left();
flipper.showPrevious();
return;
}
});
}
public void groups_func()
{
Button back;
back = (Button)findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
im_going_right();
flipper.showPrevious();
return;
}
});
}
public void im_going_right()
{
Animation s_in = AnimationUtils.loadAnimation(this, R.layout.slideinleft);
Animation s_out = AnimationUtils.loadAnimation(this, R.layout.slideoutright);
this.flipper.setInAnimation(s_in);
this.flipper.setOutAnimation(s_out);
}
public void im_going_left()
{
Animation s_in = AnimationUtils.loadAnimation(this, R.layout.slidein);
Animation s_out = AnimationUtils.loadAnimation(this, R.layout.slideout);
this.flipper.setInAnimation(s_in);
this.flipper.setOutAnimation(s_out);
}
}
song_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
如果有人帮助我,我将非常感激。提前谢谢你
Your content must have a ListView whose id attribute is 'android.R.id.list'
如果您正在使用列表活动,则必须具有id为“@android:id/list”的listView
您正在扩展一个ListActivity,它要求您在布局中有一个id为@android:id/list的ListView。尝试在main.xml中更改此选项:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
为此:
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
如果要扩展ListActivity,则必须在布局中具有id为@android:id/list
的ListView。我有它,但仅在我的flipper的第二个布局中。所以我的问题是如何让系统看到它。@user1493420很高兴我能帮忙!请单击我答案左上角的复选标记,表示此问题已解决。
Your content must have a ListView whose id attribute is 'android.R.id.list'
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=” “
android:id=”@+id/selection”
/>
<ListView
android:id=”@android:id/list”
android:choiceMode=”multipleChoice”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”/>
</LinearLayout>
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>