1

私は ListActivity を拡張するクラス MainActivity を持っていますonResume()。メソッド内のカスタム アダプターを介してリストにアダプターを設定します。

@Override
protected void onResume() 
{
    super.onResume();
    this.setListAdapter(null);
    adapter=new ContactListAdapter(this, R.id.txvNNPersonId, helper.getContacts(sortByname));       
    setListAdapter(adapter); 
}

リスト項目のクリックを処理するには、これを使用します

protected void onListItemClick(ListView l, View v, int position, long id) 
    { 
        RelativeLayout r=(RelativeLayout)v;
        TextView txvPersonId=(TextView)r.getChildAt(0);
        int iid=Integer.parseInt(txvPersonId.getText().toString());
        Intent intent=new Intent(this,ViewContactActivity.class);
        intent.putExtra("id", iid);
        startActivityForResult(intent, VIEW_RECORD);
        //these is not working, these event is not raised, when clicked on listitem click
    }

ただし、マウスでアイテムをクリック/タッチすると機能しません。アイテムを選択して実装して使用する場合にのみ機能しますonItemSelectedListener

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
    RelativeLayout r=(RelativeLayout)arg1;
    TextView txvPersonId=(TextView)r.getChildAt(0);
    int id=Integer.parseInt(txvPersonId.getText().toString());
    Intent intent=new Intent(this,ViewContactActivity.class);
    intent.putExtra("id", id);
    startActivityForResult(intent, VIEW_RECORD);
}

これはエミュレータの矢印キーでのみ機能しますが、実際のデバイスでは(通常)矢印/ナビゲーションキーがありません。リスト項目のクリックを定義するにはどうすればよいですか?

編集:row_item.xml

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:longClickable="true"
          android:orientation="horizontal">

 <TextView android:id="@+id/txvPersonId"
          android:layout_width="wrap_content"
          android:layout_height="40dp"
          android:visibility="invisible" />   -->

<!-- this is name -->
 <TextView android:id="@+id/txvPersonName"
          android:layout_marginLeft="5dp"             
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:gravity="center_vertical"
          android:text="asd"
          android:textSize="15sp"
          android:paddingBottom="5dp" />

 </RelativeLayout>`
4

0 に答える 0