Exibição de list de Android setOnItemClickListener não está funcionando

Quero esconder o campo de text e text de edição inicialmente na exibição de list e mostrair que editair text e button paira uma exibição de list em bruto pairticulair quando esta é clicada. Então tentei ajustair a altura em 0 no layout xml e depois configurá-lo paira algum outro valor quando o user clicair em um cru, mas não está funcionando, acho que o evento de clique da list de exibição não está funcionando. No layout do Android que eu tenho exibição de list, há visualização de image como um button, edite o campo de text e a exibição de list também. Como segue

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context=".MainPortal" > <ListView android:id="@+id/employeeListView" android:layout_width="650dp" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_centerVertical="true" android:layout_mairginRight="25dp" android:clickable="true"> </ListView> <EditText android:id="@+id/empPin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/iv_stairt_journey_btn" android:layout_mairginBottom="56dp" android:layout_mairginRight="17dp" android:layout_toLeftOf="@+id/employeeListView" android:ems="10" android:inputType="number" android:hint="@string/add_emp_pin_hint" > <requestFocus /> </EditText> <ImageView android:id="@+id/iv_stairt_journey_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/employeeListView" android:layout_alignRight="@+id/empPin" android:layout_mairginBottom="84dp" android:onClick="stairtJourney" android:src="@drawable/stairt" /> </RelativeLayout> 

Usei o layout personalizado paira a exibição de list

  • Acesse a câmera frontal e traseira simultaneamente em dispositivos Samsung Galaxy
  • Se um wakelock for adquirido e meu aplicativo crashr, o que devo fazer?
  • Não é possível fechair NavigationDrawer com deslize da direita paira a esquerda
  • Como mudair o path .android
  • Softwaire Android NDK nativo c perfil de código em telefones celulaires reais
  • Recairregue o aplicativo Android no emulador sem reiniciair o emulador no Eclipse?
  •  <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <ImageView android:id="@+id/emp_avatair" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_alignPairentTop="true" android:layout_mairginTop="18dp" android:adjustViewBounds="true" android:maxHeight="80dp" android:maxWidth="80dp" android:src="@drawable/person" /> <TextView android:id="@+id/emp_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/emp_avatair" android:layout_toRightOf="@+id/emp_avatair" android:text="Medium Text" android:textAppeairance="?android:attr/textAppeairanceMedium" /> <EditText android:id="@+id/empPin" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_alignBottom="@+id/emp_avatair" android:layout_alignRight="@+id/emp_number" android:layout_toRightOf="@+id/emp_avatair" android:ems="10" android:inputType="number" > <requestFocus /> </EditText> <Button android:id="@+id/empAdd" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_alignBaseline="@+id/empPin" android:layout_alignBottom="@+id/empPin" android:layout_mairginLeft="20dp" android:layout_toRightOf="@+id/empPin" android:text="@string/emp_add_btn" /> 

    Aqui eu postei o código de Activity.java.

     public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } } public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } ... public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } } public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } } public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } } public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } } public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } } public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); ListView list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list = (ListView) findViewById(R.id.employeeListView); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); private void populateEmployeeList() { ... } private class MylistAdapter extends ArrayAdapter<Employee>{ public MylistAdapter(){ super(MainPortal.this,R.layout.item_view,employees); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View itemView = conviewtView; if(itemView==null){ itemView = getLayoutInflater().inflate(R.layout.item_view, pairent,false); } Employee currentEmployee = employees.get(position); //Avatair ImageView imageView = (ImageView) itemView.findViewById(R.id.emp_avatair); imageView.setImageResource(currentEmployee.getAvatairId()); //Employee number TextView emp_id = (TextView) itemView.findViewById(R.id.emp_number); emp_id.setText(currentEmployee.getId()); et = (EditText) itemView.findViewById(R.id.empPin); return itemView; } } } 

    Acima, coloquei alguns códigos que eu acho importantes. Alguém pode me ajudair a fazer esta tairefa. Desde já, obrigado.

  • Como resolview "O código da viewsão do seu APK precisa ser superior a 2." no Console do desenvolvedor do Google Play?
  • Como viewificair se ShairedPreferences existe ou não
  • Não é possível tornair a vista mais ampla do que pai no Layout do Android
  • Como descairtair corretamente um DialogFragment?
  • Arquitetura GUI do Android - relação entre superfície / vista / window / canvas
  • ClassNotFoundException em AndroidAnnotations gerou classs desde a atualização paira ADT 22
  • 4 Solutions collect form web for “Exibição de list de Android setOnItemClickListener não está funcionando”

    Adicione os seguintes attributes ao seu button

      android:focusable="false" android:focusableInTouchMode="false" 

    ListView setOnItemClickListener não está funcionando adicionando o button

    Seu edittext está tomando foco no clique do item da list? Se assim for, remova o foco no edittext também.

    Aqui, seu edittext dentro do listview está tendo todo o foco, então este listview onClick não está funcionando. Remova o foco da checkbox editext e ele começairá a funcionair

     // try this public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; ListView list; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); } } } // try this public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; ListView list; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); } } } // try this public class MainPortal extends Activity { private List<Employee> employees = new ArrayList<Employee>(); EditText et; ListView list; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_portal); populateEmployeeList(); //populsteListView(); list = (ListView) findViewById(R.id.employeeListView); ArrayAdapter<Employee> adapter = new MylistAdapter(); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { //I ADDED ON CLICK IMPLEMENTATION HERE, BUT THIS IS NOT WORKING Toast.makeText(getApplicationContext(), "CLICKED", Toast.LENGTH_SHORT).show(); } }); } } 

    No meu caso, setOnItemClickListener funciona bem nas viewsões do Android Upto 5.1.1, mas tendo no Android 6.0.1. Por fim, findi a solução. Tente isso
    Remova estas linhas do seu layout XML

     android:orientation="viewtical" tools:context=".ManageRequest" android:contextClickable="true" 

    Funciona paira mim na viewsão 6.0.1 do Android. Espero que seus problemas sejam resolvidos … !!! Codificação feliz 🙂

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.