我想在一项活动中填充两个列表视图。为此,我在一个布局中放置了两个列表视图。我的问题是两个列表视图都已填充,但只有一个列表视图可见。现在,当我使一个布局不可见时,它将显示另一个列表视图。
我在这里发布我的 xml 文件。我的布局有什么问题吗?请提出解决方案。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="10dp"
android:id="@+id/playlist_lyt"
>
<Button
android:id="@+id/btnAlbumwise"
android:text="View Albumwise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RelativeLayout
android:id="@+id/layout_songlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="10dp"
android:layout_below="@+id/layout_albumlist"
>
<EditText android:id="@+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="33dp"
android:hint="Search.."
android:inputType="textVisiblePassword"
android:cursorVisible="false"
android:background="@drawable/rounded_edittext"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#000000"
android:dividerHeight="4dp"
android:listSelector="@drawable/list_selector"
android:layout_below="@+id/inputSearch"
android:paddingTop="8dp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_albumlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="10dp"
android:layout_below="@+id/btnAlbumwise"
>
<ListView
android:id="@+id/liist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#242424"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
/>
</RelativeLayout>
</RelativeLayout>
填充列表视图“列表”的代码。播放列表活动.java
Cursor cursor1 = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null,null, null, null);
if (cursor1 == null)
{
//Query Failed , Handle error.
}
else if (!cursor1.moveToFirst())
{
//No media on the device.
}
else
{
// int albumName = cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM);
int id = cursor1.getColumnIndex(MediaStore.Audio.Albums._ID);
int albumartist = cursor1.getColumnIndex(MediaStore.Audio.Albums.ARTIST);
for(int i=0;i<cursor1.getCount();i++)
{
String Name = cursor1.getString(cursor1.getColumnIndex(MediaStore.Audio.Albums.ALBUM));
Integer albumid = cursor1.getInt(id);
String artist = cursor1.getString(albumartist);
Bitmap bitmap = null;
bitmap = getArtwork(context, albumid);
lstImage.add(bitmap);
lstName.add(Name);
lstArtist.add(artist);
cursor1.moveToNext();
}
}
cursor1.close();
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < lstName.size(); i++) {
RowItem item = new RowItem(lstImage.get(i), lstName.get(i) , lstArtist.get(i));
rowItems.add(item);
}
CustomListViewAdapter adapter = new CustomListViewAdapter(PlayListActivity.this,
R.layout.list_item, rowItems);
lv1.setAdapter(adapter);
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
RowItem item = rowItems.get(position);
String title = item.getTitle();
Intent in = new Intent(PlayListActivity.this,AlbumsongListActivity.class);
// Sending songIndex to PlayerActivity
in.putExtra("albumTitle", title);
in.putExtra("list", 0);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
}
});
现在,当我单击项目时,它会启动另一个活动 Albumsonglistactivity.java
public class AlbumsongListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] from = { "songTitle", "artist" };
int[] to = { R.id.album_songTitle, R.id.album_songArtist };
adapter = new SimpleAdapter(this, getAlbumSongList(context),
R.layout.albumsonglist_item, from, to)
{
public long getItemId(int position)
{
return songsListData.indexOf(getItem(position));
}
};
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
// getting listitem index
int songIndex = (int) id;
// Starting new intent
Intent in = new Intent(getApplicationContext(),MusicPlayertemp.class);
in.putExtra("songIndex", songIndex);
in.putExtra("albumtitle", albumName);
in.putExtra("listFlag", 3);
startActivity(in);
}
});
}
public ArrayList<HashMap<String, String>> getAlbumSongList(Context c)
{
String whereClause = MediaStore.Audio.Media.ALBUM + " = ? ";
String s[] = new String[] { albumName };
Cursor cursor = c.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, whereClause,s, MediaStore.Audio.Media.TITLE);
if (cursor == null)
{
// Query Failed , Handle error.
}
else if (!cursor.moveToFirst())
{
// No media on the device.
}
else
{
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Audio.Media.DATA);
int artistcolumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
albumid = cursor.getInt(cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ALBUM_ID));
int id = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
for (int i = 0; i < cursor.getCount(); i++)
{
String thisTitle = cursor.getString(titleColumn);
String path = cursor.getString(idColumn);
String artist = cursor.getString(artistcolumn);
String ID = cursor.getString(id);
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", thisTitle);
song.put("songPath", path);
song.put("artist", artist);
song.put("id", ID);
// Adding each song to SongList
songsList.add(song);
cursor.moveToNext();
}
}
// looping through playlist
for (int i = 0; i < songsList.size(); i++)
{
// creating new HashMap
HashMap<String, String> song = songsList.get(i);
// adding HashList to ArrayList
songsListData.add(song);
}
return songsListData;
}
在专辑歌曲列表活动中,如果我单击它不会调用的项目..