我有一个onItemClick监听器。没有错误,但每次我点击ListView中的“Caloocan”都没有任何反应。
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
restauLV.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int value = (int) restauLV.getItemAtPosition(position);
if (value == 0){
Intent cal = new Intent(HopNow.this, caloocan.class);
startActivity(cal);
}
}
});
}
}
这是caloocan.java的代码
package com.example.aspiree1_472g.finalfirstpage;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class caloocan extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.caloocan);
}
}
答案 0 :(得分:0)
试试这个
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
restauLV.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position == 0){
Intent cal = new Intent(HopNow.this, caloocan.class);
startActivity(cal);
}
}
});
}
答案 1 :(得分:0)
如果使用自定义行布局。请执行以下操作
您需要在例如listview_item.xml
使用以下方法设置根布局:
android:descendantFocusability="blocksDescendants"
使用以下项设置此项目中的任何可聚焦或可点击的视图:
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"