0

カスタマイズされたリストビューが必要な Android アプリを開発しています。

次のようなカスタマイズされたリストビューが必要です。

ここに画像の説明を入力

スピーカーボタンをクリックするたびに、それが属するアイテムのコンテンツが再生されます。

リストビューにいくつのアイテムがあるか分からないので、すべてのスピーカーボタンに名前を付ける方法と、ボタンの対応するコンテンツを取得する方法が気になります!

何か案が?

ありがとう!

4

3 に答える 3

1

またはクラスを拡張して、カスタム アダプタークラスを作成する必要があります。BaseAdapterArrayAdapter

カスタム アダプター クラスを作成したら、メソッドをオーバーライドしますgetView()

以下のリンクを確認できます。

または、私のブログで ListView カテゴリを確認してください。

于 2013-05-20T03:47:50.297 に答える
1

次の方法でも実行できます。

まず最初に、必要なリストビューと音楽配列のリストを定義します

List<HashMap<String, String>> MusicArray;
ListView MusicList;

ここで、MusicArray と MusicList の両方を初期化し、曲リストの値を MusicArray に割り当てます。

xml ファイルを使用してカスタム セル レイアウトを作成する

次に、xml ファイルをレイアウトするカスタム クラス ViewHolder を作成します。

class ViewHolder {

    TextView SongName, SongDescription;
    int id;
    }

次に、以下のように BaseAdapter を拡張する Custom_Music_List を作成します。

public class Custom_Music_List extends BaseAdapter {
    Context contex;
    ViewHolder holder;

    List<HashMap<String, String>> MusicItems;
    TextView SongName, SongDescription;

    public Custom_Music_List(Context context,
            List<HashMap<String, String>> MusicArray) {

        contex = context;
        MusicItems = MusicArray;

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return MusicItems.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView,
            ViewGroup parent) {
        // TODO Auto-generated method stub

        if (convertView == null) {

            holder = new ViewHolder();

            LayoutInflater inflater = (LayoutInflater) LayoutInflater
                    .from(contex);
            convertView = inflater.inflate(R.layout.custom_music_cell, parent,
                    false);

            holder.SongName = (TextView) convertView.findViewById(R.id.SongName);
            holder.SongName.setText(MusicItems.get(position).get("SongName"));

            holder.SongDescription = (TextView) convertView.findViewById(R.id.SongDescription);
            holder.SongDescription.setText( + MusicItems.get(position).get("SongDescription"));

        }

        return convertView;
    }

}

次に、次の方法でアダプターを MusicList に設定すると、クリックされた適切なリスト項目を取得できます。

MusicList.setAdapter(new Custom_contact(ClassName.this, MusicArray));
MusicList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view,
                int position, long arg3) {

            // You will get position of row clicked from here using position, then try to access particular item from list using position

            Log.i("Song Clicked", MusicArray.get(position).get("SongName"))

            // Perform Action based upon position of song

        }
});
于 2013-05-20T04:38:59.023 に答える
0

@Paresh Mayaniによると、カスタムアダプターを作成する必要があると言われています。

ここからデモまたは参照リンクを見つけることができます。

問題が見つかった場合は、要件に従って実装できます。それから私に知らせてください。

于 2013-05-20T04:32:08.450 に答える