2

私はオンラインメディアプレーヤーを作成しています。どのユーザーが自分のプレイリストを作成できるか。 各ユーザーには異なるリストがあります。そのリストにはQuickmixという1つの項目があり、これは修正され、そのリストの一番上にあります。 Quickmixテキストの近くにアイコンを表示したいと同時に、現在再生中のプレイリスト名の近くにアイコンを表示したいとします。そのリストを表示するための 私はxmlファイル内に1つのListViewを作成しました。 とActivityを拡張するPlayListActivity.javaを作成しました。 そのクラスで私は1つArrayAdapterArrayAdapterのテキストとアイコンをアンドロイドのリストに表示するにはどうすればいいですか?

private ArrayAdapter<String> mPlayListAdapter = null; 
private ListView mPlayList = null; 
private String[] mPlayListNames = null; 

を作成しているとのonCreateメソッドに私のコードは私が唯一の活動を延長することができますPlayListActivity.java にListActivity /いずれかを拡張することはできません

setContentView(R.layout.playlist_layout); 

      mPlayList = new String[array.length ]; 
     for(int i = 0; i < length; i++) 
     { 
      mPlayListNames[i] = array[i].mPlayList; 
     } 
    mPlayList = (ListView)findViewById(R.id.playList); 
    try { 
     mPlayListAdapter = 
      new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, 
       mPlayListNames); 
     mPlayList.setAdapter(mPlayListAdapter); 
     mPlayList.setOnItemClickListener(mPlayListListener); 
    } catch(Exception e) { 
     Intent nextActivityIntent = new Intent(
      getApplicationContext(), 
      Welcome.class); 
     finish(); 
     startActivity(nextActivityIntent); 
     return; 
    } 
/** 
* Called when user clicks on any playlist name. This listener starts 
* playback of that playlist. 
*/ 
private OnItemClickListener mPlayListListener = 
    new OnItemClickListener() 
    { 
     public void onItemClick(AdapterView<?> parent, View view, 
      int position, long id) 
     { 
      Intent nextActivityIntent = new Intent(view.getContext(), 
       SomeActivity.class); 
      //Some code to start SomeActivity 
     } 
    }; 

のようなものです。

解決方法はありますか? I want o/p like this

答えて

0

あなたはListAdapterを作成する必要があります。たとえば:R.layout.listitemにあなたがボタンを作成することができ、

mPlayList.setListAdapter(new EfficientAdapter(ctx)); 

そして、どのようにあなたが理解:

private class EfficientAdapter extends BaseAdapter { 
    private LayoutInflater mInflater; 
    private Bitmap mIcon1; 
    private Bitmap mIcon2; 

    public EfficientAdapter(Context context) { 
     // Cache the LayoutInflate to avoid asking for a new one each time. 
     mInflater = LayoutInflater.from(context); 


    } 

    /** 
    * The number of items in the list is determined by the number of speeches 
    * in our array. 
    * 
    * @see android.widget.ListAdapter#getCount() 
    */ 
    public int getCount() { 

     return stations.length; 
    } 

    /** 
    * Since the data comes from an array, just returning the index is 
    * sufficent to get at the data. If we were using a more complex data 
    * structure, we would return whatever object represents one row in the 
    * list. 
    * 
    * @see android.widget.ListAdapter#getItem(int) 
    */ 
    public Object getItem(int position) { 
     return position; 
    } 

    /** 
    * Use the array index as a unique id. 
    * 
    * @see android.widget.ListAdapter#getItemId(int) 
    */ 
    public long getItemId(int position) { 
     return position; 
    } 

    /** 
    * Make a view to hold each row. 
    * 
    * @see android.widget.ListAdapter#getView(int, android.view.View, 
    *  android.view.ViewGroup) 
    */ 

    public View getView(final int position, View convertView, ViewGroup parent) { 
     // A ViewHolder keeps references to children views to avoid unneccessary calls 
     // to findViewById() on each row. 

     // When convertView is not null, we can reuse it directly, there is no need 
     // to reinflate it. We only inflate a new View when the convertView supplied 
     // by ListView is null. 
     if (convertView == null) { 

      convertView = mInflater.inflate(R.layout.listitem, null); 

      // Creates a ViewHolder and store references to the two children views 
      // we want to bind data to. 

      TextView textView = (TextView) convertView.findViewById(R.id.text1); 
      textView.setText(stations[position]); 


     } else { 
      // Get the ViewHolder back to get fast access to the TextView 
      // and the ImageView. 

     } 


     return convertView; 
    } 



} 

このアダプタは、あなたはそのように使用することができます。メソッドgetView - このボタンを処理する必要があります。

UPD:使用ビットマップの Exemple: あなたはgetViewメソッドでこれを追加することができます。

ImageView im = new ImageView(this); 
im.setImageBitmap(bitmap); 
convertView.addView(im); 
+0

を助けるかもしれない、私は交換する必要がありますmPlayList.setAdapter(mPlayListAdapter);とmPlayList.setListAdapter(新しいEfficientAdapter(getApplicationContext())); – shankey

+0

はい。 EfficientAdapterでは任意の数のボタンを作成できます – Anton

+0

Button - これは例です。任意のビューを作成できます。 – Anton

関連する問題