0

友達を助けてください。このプログラムの何が問題なのですか。ここでは LayoutInflater を使用できません。この問題を解決する方法。

public class MyListAdapter extends ArrayAdapter<MyData> implements
        OnClickListener {

    private ArrayList<MyData> items;
    Context context;

    public MyListAdapter(Context context, int textViewResourceId,
            ArrayList<MyData> items) {
        super(context, textViewResourceId, items);
        this.items = items;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }

        MyData myData = items.get(position);
        if (myData != null) {
            TextView textViewTwo = (TextView) v
                    .findViewById(R.id.text_view_two);
            if (textViewTwo != null) {
                textViewTwo.setText(myData.getText());
                // put the id to identify the item clicked
                textViewTwo.setTag(myData.getId());
                textViewTwo.setOnClickListener(this);
            }
        }
        return v;
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        Log.d("Sample", "Clicked on tag: " + v.getTag());
        Toast.makeText(context, "", Toast.LENGTH_SHORT).show();

    }

}

エラー: メソッド getSystemService(String) はタイプ MyListAdapter に対して定義されていません。

前もって感謝します。

4

3 に答える 3

2

使用する

LayoutInflater vi = (LayoutInflater)
                      context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

それ以外の

LayoutInflater vi = (LayoutInflater) 
                  getSystemService(Context.LAYOUT_INFLATER_SERVICE);

forgetSystemServiceは の代わりに Context クラスのメソッドであるためですArrayAdaptergetSystemServiceメソッドにアクセスするには、コンテキストインスタンスを使用する必要があります

于 2013-02-20T05:26:50.953 に答える
1

context.getStystemService()このようにしてみてください

 LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
于 2013-02-20T05:27:32.043 に答える
1

アクティビティのコンテキストを使用してシステム サービスを取得する

これがインフレータの正しい呼び方です。

LayoutInflater vi = (LayoutInflater) コンテキスト。getSystemService(Context.LAYOUT_INFLATER_SERVICE);

于 2013-02-20T05:39:38.573 に答える