是的,我知道这已被问过很多次了。我尝试了所提供的所有解决方案但不适合我。所以我再次提出同样的问题。
这是我的布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:background="@drawable/view_selector"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal"
android:padding="3dp">
<TextView android:id="@+id/calcName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:layout_weight="0.9"
android:gravity="start"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textIsSelectable="false"
android:textColor="#FF000000" />
<ImageView android:id="@+id/nextImg"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="end|right"
android:layout_weight="0.1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:contentDescription="@string/strImg"
android:src="@drawable/next" />
</LinearLayout>
正如你所看到的那样,即使根视图也能使每个视图都松散焦点。
然后这是我的适配器类
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.everythingrf.android.rfcalculators.R;
import java.util.ArrayList;
import java.util.List;
public class CommonListAdapter extends ArrayAdapter<String> {
private Context mContext;
private ArrayList<String> mDataObjects;
private int layout;
public CommonListAdapter(Context context, int resource, ArrayList<String> objects) {
super(context, resource, objects);
mContext = context;
layout = resource;
mDataObjects = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(layout, parent, false);
holder.calcName = (TextView) convertView.findViewById(R.id.calcName);
holder.nextImg = (ImageView) convertView.findViewById(R.id.nextImg);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.calcName.setFocusable(false);
holder.nextImg.setFocusable(false);
holder.calcName.setText(mDataObjects.get(position));
return convertView;
}
public static class ViewHolder{
TextView calcName;
ImageView nextImg;
}
}
甚至尝试使用适配器
这是我调用onItemClickListener
的主类myCalcList.setOnItemClickListener(this);
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) {
Log.e("Main","item click");
String selectedCalc = commonList.get(pos);
openSelectedCalc(selectedCalc);
}
提前致谢:)
答案 0 :(得分:1)
请删除android:clickable =&#34; true&#34;从行布局,这将工作。
由于每一行都在使用阻止listview执行onItemClick的事件。
答案 1 :(得分:0)
如果你在onCreate方法中从ListActivity扩展yout Main,你必须添加像
这样的东西getListView().setOnItemClickListener(this);
中有一个自定义ListView示例