ArrayAdapterを使用して曲のリストを正しく表示するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/2672478

  •  28-09-2019
  •  | 
  •  

質問

配列アダプターを使用して曲のリストを表示しようとしています。しかし、問題はリストを表示できず、プリセットの背景を持つ空の画面のみが表示されていることです。これがコードです...あなたはすべてのクラスです... plzは私を助けます...

public class SongsAdapter extends ArrayAdapter<SongsList>{
private Context context;
TextView tvTitle;
TextView tvMovie;
TextView tvSinger;
String s;


    public SongsAdapter(Context context, int resource,
            int textViewResourceId, String title) {
        super(context, resource, textViewResourceId);
        this.context=context;
    }


public View getView(int position, View convertView, ViewGroup parent) {
    final int i=position;   

    List<SongsList> listSongs = new ArrayList<SongsList>();
    String title = listSongs.get(i).gettitleName().toString();

    String album = listSongs.get(i).getmovieName().toString();
    String artist = listSongs.get(i).getsingerName().toString();
    String imgal = listSongs.get(i).gettitleName().toString();

    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    View v = inflater.inflate(R.layout.row, null); 
    tvTitle=(TextView)v.findViewById(R.id.text2);
    tvMovie=(TextView)v.findViewById(R.id.text3);
    tvSinger=(TextView)v.findViewById(R.id.text1);
    tvTitle.setText(title);
    tvMovie.setText(album);
    tvSinger.setText(artist);

    final ImageView im=(ImageView)v.findViewById(R.id.image);
        s="http://www.gorinka.com/"+imgal;
         String imgPath=s;
        AsyncImageLoaderv asyncImageLoaderv=new AsyncImageLoaderv();
        Bitmap cachedImage = asyncImageLoaderv.loadDrawable(imgPath, new AsyncImageLoaderv.ImageCallback() {
            public void imageLoaded(Bitmap imageDrawable, String imageUrl) {

                im.setImageBitmap(imageDrawable);
           }
          });
         im.setImageBitmap(cachedImage);

       return v;

}   

 public class imageloader implements Runnable{

        private String ss;
        private ImageView im;

         public imageloader(String s,  ImageView im) {
             this.ss=s;
             this.im=im;
             Thread thread = new Thread(this);
             thread.start(); 
            }
        public void run(){
             try {

                 HttpGet httpRequest = null;            
                  httpRequest = new HttpGet(ss);
                  HttpClient httpclient = new DefaultHttpClient();
                    HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
                    HttpEntity entity = response.getEntity();
                    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
                     InputStream is = bufHttpEntity.getContent();

                     Bitmap bm = BitmapFactory.decodeStream(is);
                     Log.d("img","img");

                     is.close();
                     im.setImageBitmap(bm);

             } catch (Exception t) {
                Log.e("bitmap url", "Exception in updateStatus()", t);

            }

     } 
 }
}

public class SongsList {

private String titleName;
private String movieName;
private String singerName;
private String imagePath;
private String mediaPath;
// Constructor for the SongsList class
public SongsList(String titleName, String movieName, String singerName,String imagePath,String mediaPath ) {
    super();
    this.titleName = titleName;
    this.movieName = movieName;
    this.singerName = singerName;
    this.imagePath = imagePath;
    this.mediaPath = mediaPath;
}


public String gettitleName() 
{
    return titleName;
}
public void settitleName(String titleName) {
    this.titleName = titleName;
}
public String getmovieName() 
{
    return movieName;
}
public void setmovieName(String movieName) {
    this.movieName = movieName;
}
public String getsingerName() 
{
    return singerName;
}
public void setsingerName(String singerName) {
    this.singerName = singerName;
}
public String getimagePath() 
{
    return imagePath;
}
public void setimagePath(String imagePath) {
    this.imagePath = imagePath;
}
public String getmediaPath() 
{
    return mediaPath;
}
public void setmediaPath(String mediaPath) {
    this.mediaPath = mediaPath;
}


}

public class MusicListActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.openadiuofile);

    ListView list = (ListView)findViewById(R.id.list1);
    SongsAdapter adapter = new SongsAdapter(this,R.layout.row, R.id.text2, null);
    list.setAdapter(adapter);

}   

}
役に立ちましたか?

解決

ArrayAdapterには、適切に動作するアイテムのリストが必要です。現時点では、GetViewメソッドで空のリストを作成し、その後アイテムをリクエストしようとしています。この関数は決して呼び出されないため、プログラムをchrashingしなくてはしかできません。

現時点では、ListViewが表示されていることが表示されます。リストビューは、基礎となるアダプターにアダプターにあるアイテムの数を尋ねます。 ArrayListAdapterは、このアダプターを定義する内部リストのサイズを返します。そのようなリストをArrayAdapterに提供することはありません。そのため、アダプターは空のリストから始まり、何かを追加しないと、リストアクティビティのランタイム全体でアダプターが空のままになります。

これを解決する最も簡単な方法は、アダプターを作成する前に表示する前に、すべてのソングリストのリストを作成することです(オブジェクトがリストではないため、名前の最良の選択ではありません)。 スーパーコンストラクター アダプターのコンストラクター。これで、アダプターが適切に動作し、GetViewメソッドを呼び出すことができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top