0

customCursorAdapter から入力されたリストから clickOnItem を機能させることができませんでした。私はすべての設計ドキュメントと、この領域および関連領域に関連する投稿を読みましたが、すべての試みが失敗しました。助けてください!

リストには問題なく入力されますが、リスト項目をクリックすると、「そのようなメソッドの例外はありません」というエラーが表示されます onItemClick [class android.view.View]

次のコードを使用して、データベース クエリから一連のデータを出力しています。

import android.app.Activity;
import android.app.ListActivity;
import android.database.SQLException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListTripsActivity extends Activity
{

    private CustomCursorAdapter customAdapter;
    private DbHelper databaseHelper;
    private static final int ENTER_DATA_REQUEST_CODE = 1;
    private ListView listView;     
    private static final String TAG = ListTripsActivity.class.getSimpleName();

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);  
        databaseHelper = new DbHelper(this);                       
        customAdapter = new CustomCursorAdapter(this, databaseHelper.getTripList(DbHelper.DESC), 0);    
        listView = (ListView) findViewById(R.id.list); 
        listView.setAdapter(customAdapter); 

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d(TAG, "clicked on item: " + position);
            }
        });  
    }

私の activity_list.xml は次のとおりです。

 <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical"
              android:descendantFocusability="blocksDescendants"
               android:theme="@style/AppTheme" >

     <!-- This ListView is populated by customCursorAdapter -->
     <!-- The content layout is defined by row_layout.xml   -->

    <ListView android:id="@+id/list"
              android:layout_height="match_parent"
              android:layout_width="match_parent"              
              android:layout_weight="1"/>

    <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:layout_marginTop="5dp"
            android:text="Change Name"
            android:onClick="onClickEnterData"/>

    </LinearLayout>

row_layout.xml が続き、クリックしようとしているのは 2 つの TextView 項目です。

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

   <EditText  android:id="@+id/activityId"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textSize="12sp"
              android:paddingBottom="5dp" />

    <EditText android:id="@+id/activityName"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:inputType="text"
              android:textSize="12sp"
              android:paddingBottom="5dp"
              android:imeOptions="actionSend" />

    <TextView android:id="@+id/startDate"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:onClick="onItemClick"                
              android:clickable="true"  
              android:textSize="12sp"
              android:paddingBottom="5dp" />

    <TextView android:id="@+id/endDate"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:onClick="onItemClick"                
              android:clickable="true"
              android:textSize="12sp"
              android:paddingBottom="5dp" />

    </LinearLayout>

あなたの助けは大歓迎です!

4

1 に答える 1

0

@Raghunandan そうです。このコードは、ListActivity を使用し、setAdapter を使用してアダプタを listView に割り当てている例から取得しました。

それ以外の

setAdapter(customAdapter); 

使用する

listview.setAdapter(customAdapter)
于 2013-06-19T22:38:42.497 に答える