2010-08-10 8 views
2

다음은 클릭시 토스트를 등록하지 않습니다. 사실, 클릭을 감지하지 못하는 것 같습니다. CustomListTitle이 확장하는 부모 클래스는 ListActivity이므로 모든 것이 설정되어야하지만 작동하지 않습니다. 오류가 없으며 단지 클릭을 등록하지 않습니다.안드로이드의 ListView에서 onListItemClick()이 작동하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#FF0081D3" 
    android:padding="10dip" 
    android:textStyle="bold" 
    android:inputType="textCapWords" 
    android:capitalize="words" 
    android:focusable="false" 
    /> 

어떤 아이디어 : ListView에이 채우는 데 사용 여기 내 clientsrow 레이아웃 것

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:id="@+id/widget55" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:descendantFocusability="blocksDescendants" 
    > 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Choose a current client:" 
    android:textStyle="bold" 
    android:layout_margin="3dip" 
    /> 


    <ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:descendantFocusability="blocksDescendants" 
    /> 

    <TextView android:id="@android:id/empty" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="There are no Clients yet." 
     /> 


</LinearLayout> 

그리고 :

package com.mtp; 

import android.app.Activity; 
import android.app.ListActivity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ListView; 
import android.widget.SimpleCursorAdapter; 
import android.widget.Toast; 

public class AvoidForeclosure extends CustomListTitle { 

// create variables 
private DbAdapter db; 
private SimpleCursorAdapter adapter; 
private ListView list; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // set to main layout 
     setContentView(R.layout.main); 

     // set title 
     this.title.setText("Avoid Foreclosure"); 

     // open new DB connection 
     db = new DbAdapter(this); 
     db.open(); 

     // Get all the clients and manage the cursor 
     Cursor c = db.fetchAllClients(); 
     startManagingCursor(c); 

     String[] from = new String[] { DbAdapter.KEY_NAME }; 

     int[] to = new int[] { R.id.text1 }; 

     // Create an array adapter and set it to display using our row 
     adapter = new SimpleCursorAdapter(this, R.layout.clientsrow, c, from, to); 

     // Set the adapter 
     setListAdapter(adapter); 

     // get the list and set some data 
     list = getListView(); 

     list.setTextFilterEnabled(true); 

     list.setClickable(true); 

} 

    @Override 
    protected void onListItemClick(ListView list, View v, int position, long id) { 
    // TODO Auto-generated method stub 

    // get the selection then attempt to make a Toast 
    String selection = list.getItemAtPosition(position).toString(); 
    Toast.makeText(this, selection, Toast.LENGTH_LONG).show(); 

     // Comment these out for now until I get a working Toast. 
     //Intent intent = new Intent(); 
    //intent.setClass(v.getContext(), CurrentMarketValue.class); 
    //intent.putExtra("clientId", clientData.getInt(0)); 
    //startActivity(intent); 

    super.onListItemClick(list, v, position, id); 
    } 


} 

그리고 여기 내 주요 레이아웃입니까? 고맙습니다! 나는 너무 붙어 있고 마감 시간에있다.

답변

2

android:descendantFocusability="blocksDescendants" (두 번 발생) 및 android:focusable="false"을 제거하십시오. 어느 쪽도 설정 한 구조에 적합하지 않습니다. 또한, 나는 왜 당신이 list.setClickable(true);라고 부르는 지 알지 못합니다.

관련 문제