0

以下にコードを示します。リストビュー用の単純なアダプターを実装しました。しかし、私はonListItemClickに入ることができません。誰でも提案できますか?

実際にはリストは正常に表示されますが、onitemclick イベントを取得できません。前もって感謝します。

            public class MyListActivity extends ListActivity {


        @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                ArrayList<Frame> results = WebOperations
                        .loadList_Frame();
                myAdapter = new MyListAdapter(MyListActivity.this);
                myAdapter.internalList = results;

                setListAdapter(myAdapter);
                myAdapter.notifyDataSetChanged();

        };

        @Override
            protected void onListItemClick(ListView l, View v, int position, long id) {
                String item = (String) getListAdapter().getItem(position);
                Toast.makeText(this, item + " please show toast!!!!!!!!!", Toast.LENGTH_LONG).show();
            }


        public static class MyListAdapter extends BaseAdapter {

                public ArrayList<Frame> internalList;
                public LayoutInflater mInflater;
                public int pageCount = 0;
                public MyListAdapter(Context context) {
                    mInflater = LayoutInflater.from(context);
                }
                public int getCount() {
                    if (internalList == null)
                        return 0;
                    return internalList.size();
                }
                public Object getItem(int position) {
                    if (internalList == null || internalList.size() < position)
                        return null;
                    return internalList.get(position);
                }
                public long getItemId(int position) {
                    if (internalList == null || internalList.size() < position)
                        return 0;
                    return internalList.get(position).getId();
                }
                public View getView(int position, View arg1, ViewGroup parent) {
                    View v = arg1;
                    if ((v == null) || (v.getTag() == null)) {
                        v = mInflater.inflate(R.layout.entryrow, null);
                        try {
                            String gunlukText = String.format(" %s ",
                                    internalList.get(position).getKeyText().toString());
                            TextView entry = (TextView) v
                                    .findViewById(R.id.textViewEntryText);
                            entry.setText((CharSequence) gunlukText);
                        } catch (Exception e) {
                            Log.d("aaaaaaaaaaaaaaaaaaa", "errorrrrrrrrrrr");
                        }
                    }
                    return v;
                }

            }
            }

編集 1: 以下の entry_row レイアウト xml ファイルを追加しています。

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textViewEntryText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textMultiLine"
                android:padding="5dp"
                android:paddingLeft="10dp"
                android:text="@string/Ana_Sayfa"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </LinearLayout>
4

4 に答える 4

2

リストビューにリスナーを追加することを検討する必要があります。

getListView().setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
       String item = (String) getListAdapter().getItem(position);
       Toast.makeText(this, item + " please show toast!!!!!!!!!", Toast.LENGTH_LONG).show();
    }
});
于 2012-02-29T08:54:29.167 に答える
1

ビューを返す直前に onclicklistener を getView メソッドに追加します。

v.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Log.w("position", position + "");
                }
            });

それが役立つかどうかを確認してください..

于 2012-02-29T09:31:17.263 に答える
0

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List13.htmlのカスタム BaseAdapter の API デモにある良い例の 1 つを参照してonListItemCLickedください。 . それは完全にうまく機能します。それに応じてコードを変更してみてください。

于 2012-02-29T09:20:51.767 に答える